当ViewModel上的IsBusy布尔属性为True时,有一个动画的按钮:
<Button x:Name="button" Grid.Row="4"
Command="{Binding QuitCommand}"
Content="{x:Static r:Resources.Close}"
RenderTransformOrigin="0.5,0.5">
<Button.Style>
<Style TargetType="Button">
<Style.Triggers>
<DataTrigger Binding="{Binding IsBusy}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource TestStoryboard}"/>
</DataTrigger.EnterActions>
</DataTrigger> **<-- here is line 167 position 27**
</Style.Triggers>
</Style>
</Button.Style>
<Button.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Button.RenderTransform>
</Button>
故事板:
<Window.Resources>
<Storyboard x:Key="TestStoryboard">
<DoubleAnimationUsingKeyFrames
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="25"/>
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="180"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
如果我将IsBusy属性初始化为false然后稍后启动动画,那么一切正常。
如果我将IsBusy属性初始化为true,则会出现以下错误:
'[Unknown]'属性未指向路径中的DependencyObject '(0)(1)[2]。(2)'。 '设置财产 'System.Windows.FrameworkElement.Style'引发了异常。线 数字'167'和行位置'27'。
视图模型:
public const string IsBusyPropertyName = "IsBusy";
private bool _IsBusy = true;
public bool IsBusy
{
get
{
return _IsBusy;
}
set
{
if (_IsBusy == value)
{
return;
}
RaisePropertyChanging(IsBusyPropertyName);
_IsBusy = value;
RaisePropertyChanged(IsBusyPropertyName);
}
}
计时问题?
答案 0 :(得分:2)
设置
<Button.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Button.RenderTransform>
前
<Button.Style>
<Style TargetType="Button">
<Style.Triggers>
<DataTrigger Binding="{Binding IsBusy}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource TestStoryboard}"/>
</DataTrigger.EnterActions>
</DataTrigger> **<-- here is line 167 position 27**
</Style.Triggers>
</Style>
</Button.Style>
如果它已经是真的那么它会在设置RenderTransform之前调用storyboard。我相信。