切换按钮的边框颜色不会更改?

时间:2016-07-28 23:35:04

标签: c# wpf

我有以下风格

<Style TargetType="{x:Type ToggleButton}" x:Key="ListToggleButton">
            <Setter Property="FontSize" Value="15" />
            <Setter Property="SnapsToDevicePixels" Value="True" />
            <Setter Property="Foreground" Value="#FF232A2E"/>
            <Setter Property="Background" Value="White"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ToggleButton}">
                        <Border Background="{TemplateBinding Background}" BorderBrush="#FFECECEC" BorderThickness="0,0,0,1">
                            <Grid>
                                <ContentPresenter x:Name="MyContentPresenter" Content="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,0" />
                            </Grid>
                        </Border>
                        <ControlTemplate.Triggers>

                            <Trigger Property="IsChecked" Value="False">
                                <Setter Property="Background" Value="#FF232A2E"/>
                                <Setter Property="BorderBrush" Value="#FFECECEC"/>
                                <Setter Property="BorderThickness" Value="0,0,0,1"/>
                            </Trigger>

                            <Trigger Property="IsChecked" Value="True">
                                <Setter Property="Background" Value="#FFF5F5F5"/>
                                <Setter Property="BorderBrush" Value="#FF25a0da"/>
                                <Setter Property="BorderThickness" Value="0,0,0,2"/>
                            </Trigger>

                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

我想在选中按钮时更改边框颜色,背景更改但边框没有!

我想念的是什么

提前致谢

1 个答案:

答案 0 :(得分:1)

您需要指定边框的名称,并在TargetName的{​​{1}}下指定。省略Setter时,它将设置触发器所有者的属性值(在本例中为TargetName本身)。 ToggleButton setter正在运行,因为边框的背景是模板绑定到togglebutton的背景属性。

Background