將問題移至資源字典以便在我的應用程序中使用時遇到問題。Reasource字典和故事板
基本上想要在多個用戶控件上使用相同的故事板。
資源Dicitionary
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Storyboard RepeatBehavior="Forever" x:Key="AnimateWidth">
<DoubleAnimation Storyboard.TargetProperty="Width" From="1" To="250" Duration="0:0:2" BeginTime="0:0:0" FillBehavior="Stop" />
</Storyboard>
</ResourceDictionary>
用戶控件
<UserControl x:Class="Toolset.WMIControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:View="clr-namespace:Toolset"
Name="WmiControl_UserControl"
Loaded="UserControl_Loaded"
mc:Ignorable="d"
>
<UserControl.Resources>
<ResourceDictionary x:Key="Animations">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="AnimationStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<DockPanel Name="DockPanel1" Style="{StaticResource Animations}">
<DockPanel.Triggers>
<EventTrigger RoutedEvent="Loaded">
<BeginStoryboard Storyboard="{Binding AnimateWidth, Source={StaticResource Animations}}"/>
</EventTrigger>
</DockPanel.Triggers>
</DockPanel>
不是真的知道在哪裏我已經錯在這裏。任何幫助,將不勝感激。 得到錯誤「必須有一個Storyboard對象引用在此之前觸發動作可以執行。
在'BeginStoryboard'嘗試使用'StaticResource'這樣的:' ''在ResourceDictionary'鍵是不需要,'x:Key =「動畫」'必須刪除。 –