我有一個用戶控件WPF(MainControl - 在以下代碼中未示出),其中包含另一個(在下面的代碼稱爲MyControl)。
MainControl將它的DataContext設置爲一個具有Project-property屬性的對象。 當MainControl加載時,Project-property始終爲空。
問題:
當MainControl負荷,我想用一種特殊的情節串連圖板在MyControl褪色(只用這一個時間(這個「specialFadeInStoryboard」從0變爲MyControl的不透明度屬性爲1)
當Project-property設置爲非null值時,我希望MyControl使用「fadeOutStoryboard」(將MyControl的Opacity-property更改爲0)淡出,如果它之後設置爲null,我想使用「fadeInStoryboard」(將MyControl的Opacity-property更改爲1)在此時再次淡入。
但是,在爲「specialFadeInStoryboard」添加代碼後,MyControl從不會淡出......
我在做什麼錯?
<local:MyControl Visibility="{Binding RelativeSource={RelativeSource Self}, Path=Opacity, Converter={StaticResource opacityToVisibilityConverter}, Mode=OneWay}">
<local:MyControl.Style>
<Style>
<Style.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource specialFadeInStoryboard}"/>
</EventTrigger>
<DataTrigger Binding="{Binding Project, Converter={StaticResource nullToBooleanConverter}, Mode=OneWay}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource fadeOutStoryboard}"/>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource fadeInStoryboard}"/>
</DataTrigger.ExitActions>
</DataTrigger>
</Style.Triggers>
</Style>
</local:MyControl.Style>
</local:MyControl>
感謝回答,但標籤給我這個錯誤時,EnterActions是火災: 出現InvalidOperationException:「specialFadeInStoryboard的名字不能在名稱範圍發現'System.Windows.Style'。 我甚至嘗試過移動故事板,以便它是的一個孩子......但是這也不起作用:( –
kennethkryger
2010-04-15 06:45:41
通過創建af Style來解決它,使用Setter爲「Template 「。模板的值是一個ControlTemplate,所有故事板都在」ControlTemplate.Resources「部分中定義。 – kennethkryger 2010-05-21 12:56:16