【发布时间】:2019-10-01 09:58:04
【问题描述】:
每当单击按钮时,我都会尝试向按钮添加背景颜色,并在一段时间后恢复其原始颜色。我尝试创建 ResourceDictionary.xaml 并添加了我的样式集并将其引用添加到 XAML 页面。我的代码似乎有问题。如果我将样式直接添加到按钮标签中,它可以工作.. 但不是通过 ResourceDictionary 。请帮忙。
ResourceDictionary.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:FantasyPlay">
<Style TargetType="Button">
<Setter Property="Background" Value="Gainsboro" />
<Style.Triggers>
<Trigger Property="IsPressed" Value="True">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="(Button.Background).(SolidColorBrush.Color)" From="Orange" To="Gainsboro" Duration="0:0:0.50" AutoReverse="True" />
<ColorAnimation Storyboard.TargetProperty="(Button.Background).(SolidColorBrush.Color)" From="Gainsboro" To="Orange" Duration="0:0:0.1" AutoReverse="True" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
</Trigger>
</Style.Triggers>
</Style>
MyXAML:
我已经引用它像
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ResourceDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
【问题讨论】:
标签: c# wpf xaml resourcedictionary