I’m digging deeper into WPF and learning more about XAML, web-XAML and XBAP. This evening i’ve stumbled across a nasty side-effect. When i’m creating an XBAP project in Visual Studio and run it without the debugger, the XBAP gets cached somewhere and any subsequent changes don’t show up – It keeps running the old XBAP file.

I’ve done a little digging and found out that the XBAP is cached by Click-Once when you run it outside the debugger. When executed, the application is deployed and run using Click-Once which (amongst other things) versions the assembly, checks for dependencies on the target machine and loads the application. If the application has been cached, then it will use the cached version instead. However you don’t have this problem when you’re running through the debugger because the process is launched by Visual Studio, and it will always run the latest assembly. This bugs me because I more frequently run my development apps outside the debugger and only attach when I need to. I know when my code is generally going to work, and most errors can be spotted without the need for attaching a debugger to the process.

Anyway the temporary solution is to add a pre-build event which clears the Click-Once cache and upon execution, the correct version of my app will be spawned. The command for the event is:

%windir%system32rundll32 %windir%system32dfshim.dll CleanOnlineAppCache

You can also run the command mage.exe -cc which is a CLI tool to do the same thing. More research is required into Click-Once and all this. Please note that this is a preliminary post, and I haven’t done much research in depth into the problem – if you know of a better way, i’d like to hear it!

This evening I wanted to get back to my old habits of creating silly spike projects which just test out a particular piece of functionality/feature.

Tonight I have mixed together some WPF forms and binding with some LINQ queries i was learning.

Part 1 – WPF Forms and Binding
What I wanted to learn from this was to create my own ListBox with a custom drawn ListItem, and bind it to a simple List<String>. The catch was I wanted to do this without looking it up on the net thereby forcing myself to learn the framework and in particular the syntax around the Binding interpreter because there’s no IntelliSense for any Binding properties. The result XAML is below:

[HTML2]



Part 2 – LINQ Basics
Although I was watching the video, I went off and did my own thing for the most part, and was playing around with using LINQ to select a list of directories which matched a certain criteria. This sample demonstrated how to add any method as part of the filter condition for a LINQ query, and a brief touch on ordering.

[HTML1]



Part 3 – LINQ Objects

This idea is to use LINQ to return an anonymous type which is defined inline of the LINQ query itself. (ignore the bad naming convention, here 😉 )

[HTML3]



Part 4 – LINQ Grouping
This exercise was to play around with grouping of LINQ queries and the ways that you can select out of the grouped query result. I still haven’t got the knack of this one, just yet….

[HTML4]


That just about wraps it up for tonight….Not a bad way to spend my time offline

I’ve recently been getting my hands dirty with WPF as a successor to WinForms, and one thing is for sure – its like i’m starting from ground zero, all over again…

What I’ve recently wanted to do was to learn the details of animation in WPF. I’ve read a lot about the animation frameworks built into WPF, and the fact that they can be programmed directly into the XAML is quite interesting. Seems that it XAML is a whole lot more than a mark-up language. It’s so expressive it is almost like code.


<window x:Class="WPFAnimatingPath.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
</window><window .Resources>
<storyboard x:Key="pointAnimation">
<pointanimation From="55, 10" To="55, 150" RepeatBehavior="Forever" AutoReverse="True" Storyboard.TargetName="seg1" Storyboard.TargetProperty="Point1" AccelerationRatio="0.5" DecelerationRatio="0.5" Duration="0:00:10" />
<pointanimation From="105, 150" To="105, 10" RepeatBehavior="Forever" AutoReverse="True" Storyboard.TargetName="seg2" Storyboard.TargetProperty="Point1" AccelerationRatio="0.5" DecelerationRatio="0.5" Duration="0:00:05" />
</storyboard>
</window>
<grid>
<button Name="btnAnimate" Margin="0,37,0,0" Click="btnAnimate_Click">
<stackpanel Height="200" Width="160">
<textblock TextAlignment="Center" Height="40" VerticalAlignment="Bottom" FontSize="16">Click me</textblock>
<path Stroke="BlueViolet" StrokeThickness="2" Width="160" Height="160">
</path><path .Triggers>
<eventtrigger RoutedEvent="Path.Loaded">
<beginstoryboard>
<storyboard>
<doubleanimation Storyboard.TargetName="rotation" Storyboard.TargetProperty="Angle" From="-30" To="30" Duration="0:0:05" RepeatBehavior="Forever" AutoReverse="True" AccelerationRatio="0.5" DecelerationRatio="0.5" />
</storyboard>
</beginstoryboard>
</eventtrigger>
</path>
<path .RenderTransform>
<rotatetransform x:Name="rotation" CenterX="80" CenterY="80" Angle="0" />
</path>
<path .Data>
<pathgeometry>
</pathgeometry><pathgeometry .Figures>
<pathfigure StartPoint="0, 80">
<linesegment Point="30, 80" />
<quadraticbeziersegment x:Name="seg1" Point1="55, 10" Point2="80, 80" />
<quadraticbeziersegment x:Name="seg2" Point1="105, 150" Point2="130, 80" />
<linesegment Point="160, 80" />
</pathfigure>
</pathgeometry>

</path>

</stackpanel>
</button>
</grid>

What i’ve written here is a simple application which displays a button on the page. Like my last post about XAML and the mindset change, this code allows me to embed whatever i want into the content of the Button, and in this case, i have 2 bezier arcs which form a pseudo SINE wave. when you click the button, the arcs animate and flow in a throbbing fashion.

These are the basics which demonstrate:

  • Window Resources
  • Embedded Content
  • Drawing arcs/lines
  • Animating objects

I’ve recently been getting my hands dirty with WPF as a successor to WinForms, and one thing is for sure – its like i’m starting from ground zero, all over again…

One point which i’d heard while watching a screencast, is that working with WPF changes the developer mindset from “here is a visual component i wish to use” to “here is the behaviour i would like from a visual component”. I might be wrong, but i recall this as being referred to as the “visualless state” of controls. (i’ll try to find that reference and correct it).

Either way, it’s actually quite true. In WinForms, you pick a control because of the behaviour, but also because its appearance is something that (within reasonable tolerance) suits to your situation. In WPF, that concept of “the control which looks right” is gone. You can style/design your controls to look and behave in a way you would want. This was never clearer than the proof that you can turn a regular listbox as you know it in the Win32 control set to look like anything you want:

WPF Custom ListBox

…and the XAML is really straightforward – just style your item template to look exactly how you want. Good-bye owner drawing of Win32!

<pre>
<Window x:Class=”WPFCustomListBoxLayout.Window1″ xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” Title=”Window1″ Height=”300″ Width=”300″ Loaded=”Window_Loaded”>
<Grid>
<ListBox Name=”lstItems” MaxHeight=”300″>
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderBrush=”Blue” Margin=”4,0,4,0″ BorderThickness=”1″ CornerRadius=”3″>
<StackPanel Orientation=”Vertical”>
<StackPanel Orientation=”Horizontal” Background=”AntiqueWhite”>
<TextBlock FontSize=”16″ Text=”{Binding Path=FirstName}” />
<TextBlock FontSize=”16″ Text=” ” />
<TextBlock FontSize=”16″ Text=”{Binding Path=LastName}” />
</StackPanel>
<TextBlock FontSize=”12″ Text=”{Binding Path=Age}” />
<TextBlock FontSize=”12″ Text=”{Binding Path=FavouriteMovie}” />
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation=”Horizontal” />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</Grid>
</Window>
</pre>