将一个storybord移动到资源字典以便在我的enitre应用程序中使用时遇到问题。
基本上想在多个用户控件上使用相同的故事板。
Resource 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对象。
答案 0 :(得分:0)
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="AnimationStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<DockPanel Name="DockPanel1">
<DockPanel.Triggers>
<EventTrigger RoutedEvent="Loaded">
<BeginStoryboard Storyboard="{StaticResource AnimateWidth}"/>
</EventTrigger>
</DockPanel.Triggers>
</DockPanel>
答案 1 :(得分:0)
回答了我自己的问题..
这是您使用另一个文件中的ResourceDictionary动画的方法。 不使用C#,因为你没有设置视图样式,所以将它保留在视图中
<ResourceDictionary x:Key="Animations">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="AnimationStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
<DockPanel x:Name="Simple_Mode" DockPanel.Dock="Top"
HorizontalAlignment="Left"
ScrollViewer.HorizontalScrollBarVisibility="Hidden"
Resources="{StaticResource Animations}"
>
<DockPanel.Triggers>
<EventTrigger RoutedEvent="Loaded">
<BeginStoryboard Storyboard="{StaticResource AnimateWidth}"/>
</EventTrigger>
</DockPanel.Triggers>
</DockPanel>