我正试图设计一个ToggleButton
。但由于一些奇怪的原因,我无法设置Border
属性。边框不显示。
我得到的是:
我想要的是:
<Style x:Key="MyToggleButton" TargetType="ToggleButton">
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="TextOptions.TextFormattingMode" Value="Display"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="Margin" Value="0 -1 0 0"/>
<Setter Property="FontSize" Value="11"/>
<Setter Property="BorderThickness" Value="0 1 1 0"/>
<Setter Property="BorderBrush" Value="Green"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<Border x:Name="Border"
Width="62"
Height="19">
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center"
Margin="-2 -3 0 0"
RecognizesAccessKey="True" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Border" Property="Cursor" Value="Hand"/>
</Trigger>
<Trigger Property="IsChecked" Value="False">
<Setter TargetName="Border" Property="Background">
<Setter.Value>
<ImageBrush TileMode="FlipY" ImageSource="pack://application:,,,/Main/Resources/dark/images/tab_normal_bg.png" />
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="Border" Property="Background">
<Setter.Value>
<ImageBrush TileMode="FlipY" ImageSource="pack://application:,,,/Main/Resources/dark/images/tab_pressed_bg.png" />
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsChecked" Value="False">
<Setter Property="Foreground" Value="LightGray"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
答案 0 :(得分:2)
您必须实际使用控件模板中的属性BorderBrush
和BorderThickness
。仅仅设置属性是不够的 - 框架不会对如何在模板中使用它们做任何假设。
<Border x:Name="Border"
Width="62"
Height="19"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">