1

我在 Silverlight 中创建了一个自定义控件,我已将模板添加到 generic.xaml 文件资源字典中。除了模板之外,我还把 StoryBoard 对象放到了这个字典中

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:WidgetBase="clr-namespace:WidgetBase">

<Style TargetType="WidgetBase:WidgetBase">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="WidgetBase:WidgetBase">
                <Border BorderBrush="Black" BorderThickness="0" CornerRadius="10">
                    <StackPanel x:Name="FrameContainer">
                        <Border BorderBrush="Black" BorderThickness=".6"  HorizontalAlignment="Right" CornerRadius="10" Padding="3" MaxWidth="70" MaxHeight="30" Margin="5">
                            <Border.Effect>
                                <DropShadowEffect Color="Gray"></DropShadowEffect>
                            </Border.Effect>
                            <StackPanel Orientation="Horizontal">
                                <StackPanel.Resources>
                                    <Style TargetType="Image">
                                        <Setter Property="Width" Value="16"></Setter>
                                        <Setter Property="Height" Value="16"></Setter>
                                        <Setter Property="Margin" Value="3,0,3,0"></Setter>
                                        <Setter Property="Cursor" Value="Hand"></Setter>
                                    </Style>
                                </StackPanel.Resources>

                                <Image x:Name="MinimizeButton" Source="../Icons/Deep_Fav.png" />
                                <Image x:Name="RestoreButton" Source="../Icons/Deep_Faq.png" />
                                <Image x:Name="CloseButton" Source="../Icons/Deep_Close.png"/>


                            </StackPanel>
                        </Border>

                        <Border BorderBrush="Gray" x:Name="DragBorder" BorderThickness=".8"  HorizontalAlignment="Right" CornerRadius="10" Background="Black" Cursor="SizeNWSE">

                            <ContentPresenter Content="{TemplateBinding Content}"
                                                  ContentTemplate="{TemplateBinding ContentTemplate}" Margin="10"/>
                        </Border>
                    </StackPanel>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

**<Storyboard x:Key="CloseAnimation">
    <DoubleAnimation     Storyboard.TargetProperty="UIElement.Opacity"
                         Duration="00:00:02" From="1.0" To="0.0" 
                         AutoReverse="False">
    </DoubleAnimation>
</Storyboard>**

如何使用来自 Code Behind 的 Resource Dictionary 中的 Storyboard?我将点击事件连接到模板中的按钮:

 (this.GetTemplateChild("CloseButton") as Image).MouseLeftButtonDown += Close;

然后在事件处理程序中,我想在用户控件上播放动画。

请问有人可以帮忙吗?

谢谢。

4

0 回答 0