首页 > 解决方案 > 为 Mah:Tile 添加颜色动画

问题描述

我正在使用MahApps.Metro,并且正在使用加载有命名空间“MahCtrl”( xmlns:MahCtrl="http://metro.mahapps.com/winfx/xaml/controls) 的 Tile 元素。我想在和上申请ColorAnimationTile 。MouseEnterMouseLeave

这是我目前正在处理的 xaml 片段。

<UserControl xmlns:MahCtrl="http://metro.mahapps.com/winfx/xaml/controls">
   <MahCtrl:Tile Cursor="Hand" Background="Transparent" Height="200" Width="210"HorizontalContentAlignment="Center">     
        <MahCtrl:Tile.Triggers>
            <EventTrigger RoutedEvent="MouseEnter">
                <EventTrigger.Actions>
                    <BeginStoryboard>
                        <Storyboard>
                            <ColorAnimation
                                Duration="0:0:0.200"   
                                Storyboard.TargetProperty="(MahCtrl:Tile.Background).Color" 
                                To="#fffccc" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger.Actions>
            </EventTrigger>
            <EventTrigger RoutedEvent="MouseLeave">
                <EventTrigger.Actions>
                    <BeginStoryboard>
                        <Storyboard>
                            <ColorAnimation 
                                  Duration="0:0:0.250"   
                                  Storyboard.TargetProperty="(MahCtrl:Tile.Background).Color" 
                                  To="#ffffff" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger.Actions>
            </EventTrigger>
       </MahCtrl:Tile.Triggers>
    </MahCtrl:Tile>
</UserControl>

在调试部分中,当我在 Tile 中输入鼠标时发生以下异常

System.InvalidOperationException:“无法解析属性路径“(0).Color”中的所有属性引用。验证适用的对象是否支持这些属性。

我已经尝试过使用(Background).Color和许多其他组合,StoryBoard.TargetProperty但是当MahCtrl:Tile元素用堆栈面板包装并将事件触发器MouseEnterMouseLeave带有目标(StackPanel.Background).Color的触发器应用于 StackPanel 时,此方法有效。如何定位背景属性MahCtrl:Tile

如果有人可以参考有关此主题的文档,那将是一个很大的帮助

非常感谢,

标签: wpfxamlmahapps.metrocoloranimation

解决方案


推荐阅读