WPF samples not working and how to fix them

At least some samples that come with WinFX November CTP don't work because of breaking changes (I've got link via Karstern Januszewski). Take for example first page of ExpenseIt sample that you find in Demos\ExpenseIt folder of samples you unzipped. Run it and few moments later an exception sourcing from baml will be thrown saying something about VerticalGradient. If you take a look at breaking changes you'll see that VerticalGradient is mentioned. Open App.xaml, find the following line:

<Style x:Key="TotalRectangle" TargetType="{x:Type Rectangle}">

There are two setters containing VerticalGradient in their values and since the constructs inside Value are strings the errors aren't picked by compiler:

 <Setter Property="Stroke" Value="VerticalGradient #4E87D4 #73B2F5">

 <Setter Property="Stroke" Value="VerticalGradient #73B2F5 #4E87D4">

They should be transformed to this constructs:

<Setter Property="Stroke">

<Setter.Value>

<LinearGradientBrush StartPoint="0,0" EndPoint="0,1" >

<LinearGradientBrush.GradientStops>

<GradientStopCollection>

<GradientStop Offset="0" Color="#4E87D4" />

<GradientStop Offset="1" Color="#73B2F5" />

</GradientStopCollection>

</LinearGradientBrush.GradientStops>

</LinearGradientBrush>

</Setter.Value>

</Setter>

and

<Setter Property="Fill">

<Setter.Value>

<LinearGradientBrush StartPoint="0,0" EndPoint="0,1" >

<LinearGradientBrush.GradientStops>

<GradientStopCollection>

<GradientStop Offset="0" Color="#73B2F5" />

<GradientStop Offset="1" Color="#4E87D4" />

</GradientStopCollection>

</LinearGradientBrush.GradientStops>

</LinearGradientBrush>

</Setter.Value>

</Setter>

respectively. That's a bit verbose, isn't it. For some reason they removed mini language constructs - didn't have time to check it out why. Anyway, after these two changes the first page works but not the second which yields another exception. I don't go into this one though. Just wanted to show you how to fix the incompatibilities. I guess that not-all-samples-are-working syndrome is the consequence of CTP release (and not beta which is normally better prepared).

Comments (1) -

Loading