cod*_*ife 21
嗯......我认为这Separator是使用简单风格无法运作的少数元素之一.根据MSDN文档,您需要指定SeparatorStyleKey.
例如,ToolBar你会这样做:
<Style x:Key="{x:Static ToolBar.SeparatorStyleKey}"
TargetType="{x:Type Separator}">
<Setter Property="Background"
Value="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}"/>
<Setter Property="Margin" Value="0,2,0,2"/>
<Setter Property="Focusable" Value="false"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Separator}">
<Border
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
Height="1"
SnapsToDevicePixels="true"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
rud*_*ler 13
使用样式
<Style x:Key="MySeparatorStyle" TargetType="{x:Type Separator}">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}"/>
<Setter Property="Margin" Value="0,2,0,2"/>
<Setter Property="Focusable" Value="false"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Separator}">
<Border
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
Height="1"
SnapsToDevicePixels="true"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
分隔符只是一个边框元素,现在您可以按照自己喜欢的方式更改其外观?
小智 10
你可以Separator使用这段代码设置颜色:
<Separator BorderBrush="Red" BorderThickness="1"/>
请注意,该BorderThickness物业也必须适用.
或者,您可以选择使用Rectangle元素:
<Rectangle HorizontalAlignment="Stretch" Fill="Blue" Height="2"/>
修改/形状更容易一些.
| 归档时间: |
|
| 查看次数: |
19851 次 |
| 最近记录: |