正在开发"数据输入样式"程序。在某个数据组合更改后,属性 IsSaveNeed(枚举:是,否)设置为"是",并且"保存"按钮应该闪烁。
我已经能够用基本按钮让按钮闪烁
<!--Save Button-->
<Button Content=" Save Settings to File" x:Name="SaveBtn" Command="{Binding SaveCMD}" Padding="10,5" Margin= "10,0" IsEnabled="{Binding SaveEnabled}"
Background="{StaticResource {x:Static SystemColors.ControlLightBrushKey}}">
<Button.Style>
<Style TargetType="Button">
<Style.Triggers>
<DataTrigger Binding="{Binding IsSaveNeeded}" Value="Yes">
<DataTrigger.EnterActions>
<BeginStoryboard x:Name="FlashBackground">
<Storyboard BeginTime="00:00:00" RepeatBehavior="Forever" >
<ColorAnimation Storyboard.TargetProperty="Background.Color" Duration="00:00:00.75" AutoReverse="True" To="Red" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<StopStoryboard BeginStoryboardName="FlashBackground" />
</DataTrigger.ExitActions>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
我被要求将所有按钮都设置为自定义样式按钮。
<!--My Custom Buton-->
<Style x:Key="myBtn" TargetType="{x:Type Button}">
<Setter Property="Background" Value="White" />
<Setter Property="Margin" Value="0" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="Foreground" Value="{StaticResource myColorBrush}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid UseLayoutRounding="True" SnapsToDevicePixels="True">
<!--Button Content / DropShadow / Border-->
<Border Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}" CornerRadius="5" BorderThickness="1" BorderBrush="{StaticResource myColorBrush}">
<Border.Effect>
<DropShadowEffect ShadowDepth="4" Direction="330" Color="Black" Opacity="0.2" BlurRadius="4"/>
</Border.Effect>
</Border>
<Border Padding="{TemplateBinding Padding}" UseLayoutRounding="True" SnapsToDevicePixels="True">
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="{TemplateBinding Content}" SnapsToDevicePixels="True" >
<!--<TextBlock.Effect>
<DropShadowEffect ShadowDepth="4" Direction="330" Color="{StaticResource MyColor}" Opacity="0.3" BlurRadius="4"/>
</TextBlock.Effect>-->
</TextBlock>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="#FFC1C1C1" />
<Setter Property="Foreground" Value="#FFACA8A8" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{StaticResource myHoverBrush}"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="{StaticResource myColorBrush}"/>
<Setter Property="Foreground" Value="White"/>
</Trigger>
</Style.Triggers>
</Style>
我需要将IsSaveNeed数据触发器添加到此自定义按钮样式myFlashingBtn中,但是当我执行闪烁工作时,其他触发器停止工作。
如何将 IsSaveNeedFlashing 合并到我的自定义按钮样式中并保持所有触发器正常工作?MultiTrigger和MultiDataTriggers没有帮助,除非我写错了。
我相信你正在寻找BasedOn
属性(Style.BasedOn)。 这允许您从特定样式继承所有内容并对其进行添加。
<!--Save Button-->
<Button Content=" Save Settings to File" x:Name="SaveBtn" Command="{Binding SaveCMD}" Padding="10,5" Margin= "10,0" IsEnabled="{Binding SaveEnabled}" >
<Button.Style>
<Style TargetType="Button" BasedOn="{StaticResource myBtn}">
<Setter Property="Background" Value="{StaticResource {x:Static SystemColors.ControlLightBrushKey}}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsSaveNeeded}" Value="Yes">
<DataTrigger.EnterActions>
<BeginStoryboard x:Name="FlashBackground">
<Storyboard BeginTime="00:00:00" RepeatBehavior="Forever" >
<ColorAnimation Storyboard.TargetProperty="Background.Color" Duration="00:00:00.75" AutoReverse="True" To="Red" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<StopStoryboard BeginStoryboardName="FlashBackground" />
</DataTrigger.ExitActions>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
编辑:我将Background
移到了样式的二传手