none
<Color>对象不能作为DynamicResource吗? RRS feed

  • 问题

  • 我定义了一个按钮,鼠标悬浮时,做一个动画:

    <ColorAnimation Storyboard.TargetName="Border" Storyboard.TargetProperty="Background.Color" To="{StaticResource SkinButtonHoverBackground}" Duration="0:0:0.3"></ColorAnimation>

    其中“SkinButtonHoverBackground”定义在资源文件中:

    <Color x:Key="SkinButtonHoverBackground" A="255"  R="140" G="186" B="255"></Color>

    如果我使用StaticResource 就没有问题。如果换成DynamicResource,程序一启动就报错:

    按钮的样式如下:

        <Style x:Key="SkinButton" TargetType="{x:Type Button}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Border Name="Border" CornerRadius="2" Background="{DynamicResource SkinButtonBackgroundBrush}" TextBlock.Foreground="{DynamicResource SkinButtonBrush}">
                            <Border.RenderTransform>
                                <TranslateTransform></TranslateTransform>
                            </Border.RenderTransform>
                            <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True"></ContentPresenter>
                        </Border>
                        <ControlTemplate.Triggers>
                            <EventTrigger RoutedEvent="MouseEnter">
                                <BeginStoryboard>
                                    <Storyboard>
                                        <ColorAnimation Storyboard.TargetName="Border" Storyboard.TargetProperty="Background.Color" To="{DynamicResource SkinButtonHoverBackground}" Duration="0:0:0.3"></ColorAnimation>
                                    </Storyboard>
                                </BeginStoryboard>
                            </EventTrigger>
                            <EventTrigger RoutedEvent="MouseLeave">
                                <BeginStoryboard>
                                    <Storyboard>
                                        <ColorAnimation Storyboard.TargetName="Border" Storyboard.TargetProperty="Background.Color" Duration="0:0:0.3"></ColorAnimation>
                                    </Storyboard>
                                </BeginStoryboard>
                            </EventTrigger>
                            <Trigger Property="IsPressed" Value="True">
                                <Setter TargetName="Border" Property="RenderTransform">
                                    <Setter.Value>
                                        <TranslateTransform X="1" Y="1"></TranslateTransform>
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    



    da jia hao!

    2017年11月10日 11:14

全部回复