【发布时间】:2011-11-23 22:54:13
【问题描述】:
我有一个会闪烁的按钮。
我想在资源字典闪烁时更改整个按钮样式。
我想应该是这样的:
DesktopWindow.AlertButton.Style = (Style)DesktopWindow.Resources["GreenAlertButtonStyle"];
但这不起作用。我该怎么做呢?我不能简单地更改背景颜色(尽管这就是我真正想做的),因为我想保留触发器。当我现在更改按钮的背景时,鼠标悬停触发器停止工作....
按钮:
<Style TargetType="Button" x:Key="BaseAlertButtonStyle">
<Setter Property="ToolTip" Value="Show Alert List"/>
<Setter Property="Effect" Value="{DynamicResource dropShadow}" />
<Setter Property="Background" Value="{DynamicResource AlertButtonBackground}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<Border CornerRadius="5" x:Name="ButtonBorder" Margin="0,0,0,0"
VerticalAlignment="Stretch" BorderThickness="0"
BorderBrush="#ffffff" Padding="0"
Background="{TemplateBinding Background}"
HorizontalAlignment="Stretch">
<Image x:Name="alertImage">
<Image.Source>
<BitmapImage UriSource="/resources/alertIcon.png" />
</Image.Source>
</Image>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" Value="{DynamicResource ButtonRolloverBackground}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我不想听到关于搜索这个问题的消息......
【问题讨论】:
-
您检查过 DesktopWindow.Resources["GreenAlertButtonStyle"] 是否没有返回空值吗?
-
是的,所有样式都存在,甚至设置都没有问题。
-
明确我想清除旧样式并引入新样式(在明确设置背景之后)
标签: c# wpf button triggers background