0
有被動畫當在視圖模型一個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,然後我得到了以下錯誤:
'[未知]' 屬性不指向的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);
}
}
時機的問題?
怎麼樣'TestStoryboard',問題可能出在那裏。 – 2014-08-28 14:51:56
@KingKing - 故事板確實有效,但如果我從一開始就將IsBusy設置爲true,那麼就不行。我發佈它,所以你可以看到。 – 2014-08-28 14:54:36