Intermittent InavlidCastException in a UserControl.InitializeComponent() - silverlight

Here is the setup:
I have a Silverlight Control Library "Controls", in which I have a customer control defined for presenting dialogs:
public class Dialog : ContentControl
{
public Dialog()
: base()
{
DefaultStyleKey = typeof(Dialog);
}
<...normal custom control stuff...>
}
also the default style is in generic.xaml:
<Style TargetType="src_general:Dialog">
<Setter Property="Padding" Value="25"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="src_general:Dialog">
<Grid x:Name="RootElement" >
<vsm:VisualStateManager.VisualStateGroups>
<vsm:VisualStateGroup x:Name="DiakogStyleStates">
<vsm:VisualState x:Name="OkCancel">
<Storyboard>
</Storyboard>
</vsm:VisualState>
<vsm:VisualState x:Name="OkOnly">
<Storyboard>
<ObjectAnimationUsingKeyFrames Duration="0:0:0" Storyboard.TargetName="CancelButton" Storyboard.TargetProperty="Visibility" >
<DiscreteObjectKeyFrame KeyTime="0:0:0" >
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</vsm:VisualState>
<vsm:VisualState x:Name="CancelOnly">
<Storyboard>
<ObjectAnimationUsingKeyFrames Duration="0:0:0" Storyboard.TargetName="OkButton" Storyboard.TargetProperty="Visibility" >
<DiscreteObjectKeyFrame KeyTime="0:0:0" >
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</vsm:VisualState>
<vsm:VisualState x:Name="None">
<Storyboard>
<ObjectAnimationUsingKeyFrames Duration="0:0:0" Storyboard.TargetName="CancelButton" Storyboard.TargetProperty="Visibility" >
<DiscreteObjectKeyFrame KeyTime="0:0:0" >
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Duration="0:0:0" Storyboard.TargetName="OkButton" Storyboard.TargetProperty="Visibility" >
<DiscreteObjectKeyFrame KeyTime="0:0:0" >
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</vsm:VisualState>
</vsm:VisualStateGroup>
</vsm:VisualStateManager.VisualStateGroups>
<Popup x:Name="DialogPopup">
<src_general:WindowFrame x:Name="Frame">
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ContentPresenter Grid.Row="0" x:Name="ContentPresenter" Margin="{TemplateBinding Padding}"/>
<!--Action Buttons-->
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right" Margin="15">
<src_general:GlassButton x:Name="CancelButton" Content="Cancel" Margin="2"/>
<src_general:GlassButton x:Name="OkButton" Content="Ok" Margin="2"/>
</StackPanel>
</Grid>
</src_general:WindowFrame>
</Popup>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I use this dialog in a lot of places with no problem. However, in one application, nested about 3-4 usercontrols from the RootVisual, I use it the following way:
<general:Dialog x:Name="AddUpdateDialog" DialogStyle="OkCancel" Title="Add/Update Connection" Closed="AddUpdateDialog_Closed" ValidationGroup="AddConnection">
<Grid Width="300">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="Name:" Style="{StaticResource LabelText}"/>
<TextBox Grid.Row="0" Grid.Column="2" Text="{Binding Name, Mode=TwoWay}" Style="{StaticResource TextBoxInput}" MaxLength="49">
<val:ValidationManager.Validator>
<val:RequiredValidator ManagerName="AddConnection" ErrorMessage="Name is required."/>
</val:ValidationManager.Validator>
</TextBox>
</Grid>
</general:Dialog>
When I run this app I intermittently (about every 5-10 starts get the following exception:
"Unable to cast object of type System.Windows.Controls.ContentControl to type hookitupright.com.silverlight.controls.general.Dialog." that occurs in the InitializeComponent() for the parent UserControl of the above XAML.
To be specific, it occurs right here:
this.AddUpdateDialog = ((hookitupright.com.silverlight.controls.general.Dialog)(this.FindName("AddUpdateDialog")));
When I put a breakpoint there, most of the time the FindName returns a Dialog typed object, but sometimes, it returns a ContentControl (the base for Dialog) and it fails. The XAML has not changed. It is static...Since the exception is intermittent and occurs within generated code I am at a loss.
I have tried:
Moved all of the content for the Dialog into a separate UserControl - only seemed to make problem worse
Comment out parts and see when it works...well, if I comment out the TextBox completely, it no longer fails. Everything else (including the custom validation attached property) seems to have no impact.
2a. Thinking it may have something to do with the TwoWay binding to the TextBox, I removed the binding. Still fail.
UPDATE: So given (2) above I left the Textbox commented out decided to move on to other things and come back to this with hopes that something will reveal itself to me. Unfortunately, it seems to also fail with the Textbox out, just less frequently.
In addition, I have this control in the exact same configuration in another usercontrol in the same app (and at the same level in the VisualTree) and it does not fail at all. So I literally copied and pasted the failing XAML into the Main.xaml (my root visual) and of course, it does not fail there either. Assuming that the the XAML is loaded in sequence (top to bottom) the failing control is likely one of the last ones loaded. My only hypothesis now is that there is some timing thing that is happening whereby as Iam still loading the visual tree, I start to get *Completed events from the loading of the data via WCF service and that these trigger a layout before the visual tree is fully loaded which causes some ill side effects... I will test this.
The problem is that it does NOT fail every time. It blows up about 20% of the time. When it works, everything works even this dialog?
This problem is related if not the same problem: When I "fix" the invalidcast by commenting out needed functionality, I will far less frequently but intermittently get this invalid attribute (when the attribute/property is in fact there).

After much, much research and frustration, I believe it to be related to this: http://blogs.msdn.com/silverlight_sdk/archive/2008/10/24/loaded-event-timing-in-silverlight.aspx
The Loaded event in Silverlight does not match the definition of (a) what it is in WPF and consequently (b) the definition that they pasted into the Silverlight documentation from WPF
WTF???
I have modified some code based on the above and now it does not seem to fail. I wish I could tell you exactly why it did what did and why what I did fixed it (or at least masked it again??), but I can't. Maybe someone else will encounter this and can figure it out.
Here is what I was doing and what I changed:
The Textbox above makes use of an Attached Property for a Validator (like the ASP.NET validators and similar to the ones in the Silverlight Toolkit). When a Validator (base class for RequireValidator) is attached to a control, it links to the control to provide validation as an attached behavior. The trick is that it then tries to Validate() the current control. For a RequiredValidator on a TextBox control it calls string.IsNullOrEmpty() for the Text property on the linkedControl. All of this works fine as these are just properties on the TextBox Control. However, just after that, the validator needs to somehow tell the control to display the error indicator and any error message. I do this through providing a custom Style that includes two new VisualStates ("ValidInput" & "InvalidInput") in their own VisualStateGroup ("ValidationStates") and that one of the Style's Elements is a Control that supports and interface called IValidationNotificationControl.
Ok, enough background. From the documentation, I knew that I could only access the elements of the TextBox Style (the new visualStates and the notification icon) AFTER the template had been applied so I hooked into the Loaded event for the linkelement for the validator and called Validate() there for the first time. Well, someone at MS saved about 15 minutes by copying an pasting the Loaded Event description from WPF and that cost me about 3-4 days of heartache. Turns out that there is no guarantee that the template is applied then in Loaded Event in silverlight. So, I simply added a call to ApplyTemplate() in the Loaded event handler for the linkedelement and the failure went away.
My guess is that the error was intermittent because the Layout (and therefore the application of the Template) occurs asynchronously and sometimes it was there when I hit the Loaded Event and sometimes it was not. But I still think that it is a Silverlight Bug as to where the error manifested itself and may even point to a security hole (if, but some action, somewhere else in the code, I can cause the XAML Parser to return a type different than what teh actual XAMl indicates...). Oh well...it seems to be working now. Maybe this will help someone else.

Maybe this helps someone too: take a look at my answer in another thread:

Related

Setting an Initial VisualState in WPF

When using the VisualStateManager in WPF there can be a requirement to transition to a VisualState on control initialization. As far as I can tell there is no way to declare an initial state in Xaml, leaving you with the limited option of transitioning to the required state in your code behind after initialization.
Using code behind is not always desirable, and if you are using a Binding to control your VisualStates then not always possible.
So the question is: how do you set an initial VisualState in WPF without setting it in the code behind?
Too long for a comment
Binding "should" make no difference. If it works fine from code-behind it's bound to work from xaml unless there is something really weird in the Bindings.
All of blend's actions can be considered as a xaml helper tool. End result is you get some xaml that blend creates for you. If you do not want to use blend. Just add the xaml yourself in VS.
For this very thing the GoToStateAction can be coded such as
<Window ...
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
...>
...
<Button x:Name="button"
Style="{DynamicResource ButtonStyle1}">
<i:Interaction.Triggers>
<i:EventTrigger>
<ei:GoToStateAction StateName="YourState"
TargetObject="{Binding ElementName=button}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
You'll need the corresponding references in your project as well.
On a side-note do try blend. It has it's advantages in specific places. You prolly would not replace typing xaml directly, but it serves as a good helper tool. Ignoring it completely unless forced to is pointless IMO.
You can directly bind any control with visual state at the time of initialisaton itself in xaml.
You need to create one dependency property to change the state.
hope below code can help you .
<Grid model:StateManager.VisualStateProperty="{Binding VisibilityState}" >
<Grid.RowDefinitions>
<RowDefinition Height="48" />
<RowDefinition Height="97" />
<RowDefinition Height="65" />
<RowDefinition Height="297" />
</Grid.RowDefinitions>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="VisibleStateGroup">
<VisualState x:Name="VisibleState">
<Storyboard Duration="0:0:0">
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="myGrid" Storyboard.TargetProperty="(UIElement.Visibility)">
<DiscreteObjectKeyFrame KeyTime="0:0:0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="CollapsedState">
<Storyboard Duration="0:0:0">
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="myGrid" Storyboard.TargetProperty="(UIElement.Visibility)">
<DiscreteObjectKeyFrame KeyTime="0:0:0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid Name="myGrid" Grid.Row="0" Grid.ColumnSpan="2" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="383*" />
<ColumnDefinition Width="383*" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Orientation="Horizontal" Margin="0,0,15,0" HorizontalAlignment="Right" VerticalAlignment="Center">
<Label Content="MyName"></Label>
</StackPanel>
</Grid>
Dependency property code for visual state change
public class StateManager : DependencyObject
{
public static string GetVisualStateProperty(DependencyObject obj)
{
return (string)obj.GetValue(VisualStatePropertyProperty);
}
public static void SetVisualStateProperty(DependencyObject obj, string value)
{
obj.SetValue(VisualStatePropertyProperty, value);
}
public static readonly DependencyProperty VisualStatePropertyProperty =
DependencyProperty.RegisterAttached(
"VisualStateProperty",
typeof(string),
typeof(StateManager),
new PropertyMetadata((s, e) =>
{
var propertyName = (string)e.NewValue;
var ctrl = s as Grid;
if (ctrl == null)
throw new InvalidOperationException("This attached property only supports types derived from FrameworkElement.");
var transitionWorked = System.Windows.VisualStateManager.GoToElementState(ctrl, (string)e.NewValue, true);
//MessageBox.Show(transitionWorked.ToString());
}));
}

Silverlight & WPF: VisualStateManager in ControlTemplate does not work

So, hello everybody.
I've made two test programs for creating a own control. One in Silverlight, one in WPF. I created a kind of RangeSlider. This Slider has of course two Orientations, Horizontal and Vertical.
First I used two different techniques to create my RangeSlider. In WPF I used Triggers, in Silverlight (u know there arent Triggers) I changed the Visibility of the Horizontal and Vertical Template in CodeBehind.This runs.
Now:
I'm trying to use one technique for both, Silverlight and WPF. Therefore I use VisualStateManager.
I've a Template defining two Sliders (one for left value, the other for right value). Simplified on the important values it looks like that:
...
<ControlTemplate>
<Grid x:Name="PART_Content">
<!-- VSM: See following code sequence -->
<Grid x:Name="PART_HorizontalTemplate">
<Slider x:Name="PART_HorizontalSliderLeft"
Template="{StaticResource HorizontalSliderTemplate}"
Orientation="{TemplateBinding Orientation}" />
...
</Grid>
<Grid x:Name="PART_VerticalTemplate">
...
</Grid>
</Grid>
</ControlTemplate>
Additionally there is the VSM to switch between Horizontal and Vertical look:
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="Vertical">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_HorizontalTemplate"
Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame Value="{x:Static Visibility.Collapsed}" KeyTime="0"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Horizontal" />
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
This still runs.
As you see in the code sequence, the visual of Slider is defined by a Template, here HorizontalSliderTemplate (I reduce code again):
<ControlTemplate x:Key="HorizontalSliderTemplate" TargetType="{x:Type Slider}">
<Border x:Name="Border" ...>
<!-- VSM here. Like above. -->
<Grid x:Name="Grid">
<Rectangle x:Name="PART_SelectionRange"/>
<Track x:Name="PART_Track">
...
</Track>
</Grid>
</Border>
</ControlTemplate>
Actually there is also a VerticalSliderTemplate.
But I want to combine both ControlTemplate in one Template and use VSM. Here we come to my problem:
I do not get running the VSM in the 'inner' ControlTemplate. It's nearly the same code as the running VSM-Part, just the TargetName is changed. I do not know how to debug what's running on GoToState, but I believe the VSM in the template is never found and from there never execute.
I can imagine that there's just a little detail missing, but I 'cant see the wood for the trees'. Maybe there is an important thing what I do not know about Templates or about VSM, and I'm off the track.
Or do I have to trigger the 'inner' VSM from outside, or there's a possibility to access onto Elements from 'outside VSM'?
Or is there no access on VSM in 'inner' Templates?
I hope I could explain my problem good enough and there is someone, who knows a solution or maybe a keyword what I can look for. Just entering keywords VSM, ControlTemplate, Storyboard, etc. in google gives no helping hand.
Thanks in advance.
I don't think you can have multiple VSMs inside one ControlTemplate.
Why don't you just use one VSM to toggle both.
<ControlTemplate>
<Grid x:Name="PART_Content">
<Grid x:Name="PART_HorizontalTemplate">
...
</Grid>
<Grid x:Name="PART_VerticalTemplate">
...
</Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="Vertical">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_HorizontalTemplate"
Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame Value="{x:Static Visibility.Collapsed}" KeyTime="0"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Horizontal">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_VerticalTemplate"
Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame Value="{x:Static Visibility.Collapsed}" KeyTime="0"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</ControlTemplate>
So, I got a solution on it.
In the 'inner' template I added to the element I want to toggle a DataTrigger. This DataTrigger is bound to the PART_HorizontalTemplate Visibility and contains a Storyboard that do the action I need.
Maybe it's not really the kind of solution I was looking for, because it stretches the code a lot and makes it therefore looking more complex. But - and thats most important - it runs well.

Is it possible for a button click to permanently change an image's source using only a XAML trigger?

I'm trying to solve the following problem on a WPF datagrid:
I've templated the DataGrid items to contain a button - when clicked, it displays the RowDetails for the grid. I'm having trouble getting that button styled the way I want. Specifically, I want it to appear as a "hyperlink" with a small plus-sign icon next to it. When clicked to display the RowDetails, that icon should change to a minus-sign.
Here's the ControlTemplate I'm attempting to apply to the Button:
<ControlTemplate x:Key="linkButtonTemplate" TargetType="{x:Type Button}">
<StackPanel Orientation="Horizontal">
<Image x:Name="expanderIcon" Source="Images/Plus.png"/>
<TextBlock Foreground="Blue" TextDecorations="Underline" Padding="5 0 0 0">
<ContentPresenter />
</TextBlock>
</StackPanel>
</ControlTemplate>
So, when the button is clicked, I want to change that Image's Source property. And when it's clicked again, I want to change it back. I've come across the following suggested solutions, and none seem ideal:
1. Use a Trigger on the Button.IsPressed event: It works! ...Except the image reverts once the event ends. (i.e. once the IsPressed property is no longer true). So it doesn't work.
2. Use an EventTrigger: These at least let you catch the Button's Click event... and
Unlike Trigger, EventTrigger has no
concept of termination of state, so
the action will not be undone once the
condition that raised the event is no
longer true.
So, great! But they appear to only let you respond with Storyboard actions, not a simple property Setter. Unless I'm missing something, these are not meant for this scenario.
3. Use an Attached Behavior: I'm currently delving into this option, but I just can't help thinking there ought to be a XAML-contained means of doing this. If not, so be it - I'll learn Attached Behaviors.
But my hope is that someone has an angle on this that I haven't encountered.
For example, is there a way to hook the property of the DataRow containing the button that indicates if the RowDetails are currently viewable? Seems like you'd need to crack open the code behind to accomplish that, too... Am I wrong?
I would not claim that EventTriggers are not meant for this, single frame animations are fine and can even be found in the default templates of certain controls, e.g.
<VisualState Name="CalendarButtonFocused">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="CalendarButtonFocusVisual" Storyboard.TargetProperty="Visibility" Duration="0">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
So here is an example of how to change the Source that way:
<Image Name="img" Source="C:\Users\Public\1.png"/>
<Button Content="!">
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.Target="{x:Reference img}"
Storyboard.TargetProperty="Source">
<DiscreteObjectKeyFrame KeyTime="0:0:0">
<DiscreteObjectKeyFrame.Value>
<BitmapImage UriSource="C:\Users\Public\2.png"/>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Button.Triggers>
</Button>
You could use a retemplated ToggleButton for a scenario like this and bind the images visibilities to the IsChecked Property. IT would be also much easier to bind the Visibility of the RowDetails to that.

WPF - Animation to make an error message disappear

I have the following xaml in my window:
<Border Height="100" BorderBrush="Black" BorderThickness="2" CornerRadius="10" Background="PaleVioletRed" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Margin="10" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="17" FontWeight="Bold">Error Message Here</TextBlock>
</Border>
Which basically displays this:
alt text http://xs.to/thumb-4CB2_4B69F8E6.jpg
I plan to bind it's Visibility to an error state variable so it shows when an error occurs.
But I don't want to show it for a long time. I would like it to disappear/fade after 2 seconds. Is there a way to do this via XAML? Or a nice WPF way?
Something like this psudo code logic:
when (ErrorMessage.Visibility == Visible )
{
Wait(2000); // Wait 2 seconds
ErrorMessage.Visibility == Collapsed;
}
but preferable done with XAML.
My instincts tell me there is a way to do this with an animation, but I am not an animation expert and could use some help.
The other option is to try and setup a timer and control it with that.
use something like this....
<EventTrigger RoutedEvent="Page.Loaded">
<BeginStoryboard>
<Storyboard BeginTime="0:0:1">
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="image1" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame Value="{x:Static Visibility.Visible}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
change the routed event to match your needs, set the BeginTime on the storyboard to 2 mins ( or whatever ), set the targetname to your border element.

WPF - Animating gridlength in XAML

I was just wondering if it's possible to animate the height of a grid using purely XAML? I looked at this tutorial:
http://windowsclient.net/learn/video.aspx?v=70654
But it seems as though one need to write custom functions for this to work.
Can it be done just by XAML purely?
its not possible out of the box because there's no such class as a GridLengthAnimation (compare with DoubleAnimation). If such a class existed (from you, microsoft or third party) then there would be a pure XAML solution.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="0" x:Name="Row" />
</Grid.RowDefinitions>
</Grid>
...
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Row"
Storyboard.TargetProperty="Height" Duration="0:0:0.2">
<DiscreteObjectKeyFrame Value="{x:Static GridLength.Auto}" KeyTime="0:0:0.2" />
</ObjectAnimationUsingKeyFrames>

Resources