我有一个ToggleButton
,当我按下它时需要更改边框颜色。这是我的代码:
<Window.Resources>
<Style x:Key="ComboBoxToggleButton" TargetType="ToggleButton">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<Grid VerticalAlignment="Center" HorizontalAlignment="Right" Width="30" Height="15">
<Image Source="/Res/combobox_icon.PNG"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<Border Name="br" BorderBrush="Black" Background="Red" BorderThickness="1" HorizontalAlignment="Left" Height="56" Margin="60,72,0,0" VerticalAlignment="Top" Width="125"/>
<ToggleButton Margin="291,72,94,153">
</ToggleButton>
</Grid>
答案 0 :(得分:1)
我认为你正在寻找类似的东西。您也可以以相同的方式更改BorderBrush。
<Grid>
<Border Name="br">
<Border.Style>
<Style TargetType="Border">
<Setter Property="Background" Value="Red" />
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=tog, Path=IsChecked}" Value="True">
<DataTrigger.Setters>
<Setter Property="Background" Value="Blue" />
</DataTrigger.Setters>
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
</Border>
<ToggleButton Name="tog" Margin="20,20,20,20" />
</Grid>