I'm showing an expander in a modal window. If I don't toggle the expander the window will close fine. Once I've toggled it and close the window it throws an exception on the invocation of
System.Windows.Media.Animation.DoubleAnimationBase.GetCurrentValue(Object defaultOriginValue, Object defaultDestinationValue, AnimationClock animationClock)
I have the same control on another window which works fine.
I define the control as follows
<Expander Template="{DynamicResource MoreInformationExpander}">
<StackPanel>
<TextBlock Text="{Binding MoreInformationText} />
</StackPanel>
</Expander>
The template for the expander:
<ControlTemplate x:Key="MoreInformationExpander" TargetType="{x:Type Expander}">
<DockPanel HorizontalAlignment="Stretch">
<ToggleButton x:Name="ExpanderButton"
DockPanel.Dock="Bottom"
Template="{StaticResource MoreInformationExpanderButton}"
IsChecked="{Binding Path=IsExpanded, RelativeSource={RelativeSource TemplatedParent}}"
OverridesDefaultStyle="True"
HorizontalAlignment="Left">
</ToggleButton>
<ScrollViewer x:Name="ExpanderContentScrollView" DockPanel.Dock="Top"
HorizontalScrollBarVisibility="Hidden"
VerticalScrollBarVisibility="Hidden"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Bottom"
Background="{DynamicResource WindowBorderGrayBrush}"
Padding="8,4,0,0">
<ScrollViewer.Tag>
<system:Double>0.0</system:Double>
</ScrollViewer.Tag>
<ScrollViewer.Height>
<MultiBinding Converter="{StaticResource multiplyConverter}">
<Binding Path="ActualHeight" ElementName="ExpanderContent"/>
<Binding Path="Tag" RelativeSource="{RelativeSource Self}" />
</MultiBinding>
</ScrollViewer.Height>
<ContentPresenter x:Name="ExpanderContent" ContentSource="Content"/>
</ScrollViewer>
</DockPanel>
<ControlTemplate.Triggers>
<Trigger Property="IsExpanded" Value="True">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="ExpanderContentScrollView"
Storyboard.TargetProperty="Tag"
To="1"
Duration="0:0:0.4"/>
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="ExpanderContentScrollView"
Storyboard.TargetProperty="Tag"
To="0"
Duration="0:0:0.4"/>
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
The template for the Toggle Button:
<ControlTemplate x:Key="MoreInformationExpanderButton" TargetType="{x:Type ToggleButton}">
<Grid >
<TextBlock Name="Tb" Foreground="{DynamicResource BlueSolidBrush}" FontSize="14" TextDecorations="Underline"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Text" Value="Less Information" TargetName="Tb" />
</Trigger>
<Trigger Property="IsChecked" Value="False">
<Setter Property="Text" Value="More Information" TargetName="Tb" />
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Cursor" Value="Hand" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
The multiply converter:
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
double result = 1.0;
for (int i = 0; i < values.Length; i++)
{
if (values[i] is double)
{
result *= (double)values[i];
}
}
return result;
}
Exception and stack trace
An unhandled exception occurred, and the application is terminating. Error details: Cannot animate the 'Tag' property on a 'System.Windows.Controls.ScrollViewer' using a 'System.Windows.Media.Animation.DoubleAnimation'. For details see the inner exception.
=========================================================================
at System.Windows.Media.Animation.DoubleAnimationBase.GetCurrentValue(Object defaultOriginValue, Object defaultDestinationValue, AnimationClock animationClock) at System.Windows.Media.Animation.AnimationLayer.GetCurrentValue(Object defaultDestinationValue) at System.Windows.Media.Animation.AnimationStorage.GetCurrentPropertyValue(AnimationStorage storage, DependencyObject d, DependencyProperty dp, PropertyMetadata metadata, Object baseValue) at System.Windows.Media.Animation.AnimationStorage.OnCurrentTimeInvalidated(Object sender, EventArgs args)