WPF Separator(分隔符)

分隔符,如:


 

水平分隔符 XAML

<Separator Style="{StaticResource HorizontalSeparatorStyle}"/>

 水平分隔符 Style

<Style x:Key="HorizontalSeparatorStyle" TargetType="{x:Type Separator}">
    <Setter Property="Background" Value="#dfdddb"/>
    <Setter Property="Focusable" Value="false"/>
    <Setter Property="Height" Value="1"/>
    <Setter Property="SnapsToDevicePixels" Value="True"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Separator}">
                <Line Stretch="Fill" X2="1" Stroke="{TemplateBinding Background}" StrokeThickness="{TemplateBinding Height}" StrokeStartLineCap="Square" StrokeEndLineCap="Square"/>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

 

 

垂直分割符 XAML

<Separator Style="{StaticResource VerticalSeparatorStyle}"/>

 垂直分割符 Style

<!--垂直分隔符-->
<Style x:Key="VerticalSeparatorStyle" 
    TargetType="{x:Type Separator}"
    BasedOn="{StaticResource {x:Type Separator}}">
    <Setter Property="LayoutTransform">
        <Setter.Value>
            <TransformGroup>
                <TransformGroup.Children>
                    <TransformCollection>
                        <RotateTransform Angle="90"/>
                    </TransformCollection>
                </TransformGroup.Children>
            </TransformGroup>
        </Setter.Value>
    </Setter>
</Style>

 

原文参考:https://stackoverflow.com/questions/13584998/how-to-add-a-vertical-separator

posted @ 2021-06-06 22:58  microsoft-zhcn  阅读(4022)  评论(0编辑  收藏  举报