网格分割器wpf的虚线边界

本文关键字:虚线 边界 wpf 分割 网格 | 更新日期: 2023-09-27 18:12:12

有没有办法让我的边界变成虚线而不是实线呢?我只希望它出现在左边和右边,顶部和底部应该是空的。

<Grid Grid.IsSharedSizeScope="True">
    <Grid.ColumnDefinitions>
        <ColumnDefinition SharedSizeGroup="A" Width="Auto"/>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition/>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition SharedSizeGroup="A" Width="Auto"/>
    </Grid.ColumnDefinitions>
    <Label Content="Shnarf Left" Background="Azure" Grid.Column="0"/>
    <TextBlock Text="Shnarf Middle" Background="Lavender" Grid.Column="2" TextWrapping="Wrap"/>
    <Label Content="Shnarf Right" Background="Moccasin" Grid.Column="4"/>
    <GridSplitter Grid.Column="1" Width="8"
                  HorizontalAlignment="Center" VerticalAlignment="Stretch" ShowsPreview="True" BorderBrush="Black" BorderThickness="1,0,1,0"/>
    <GridSplitter Grid.Column="3" Width="8" Background="DarkSlateBlue"
                  HorizontalAlignment="Center" VerticalAlignment="Stretch" ShowsPreview="True"/>
</Grid>

网格分割器wpf的虚线边界

下面的代码可以正常工作&您可以自定义它,因为你喜欢!注意,Viewport决定了线条中虚线的大小。在本例中,它生成8像素的破折号。Viewport="0,0,4,4"会给你4个像素的破折号。边境的:

<Border BorderThickness="1,0,1,1">
    <Border.BorderBrush>
        <DrawingBrush Viewport="0,0,8,8" ViewportUnits="Absolute" TileMode="Tile">
            <DrawingBrush.Drawing>
                <DrawingGroup>
                    <GeometryDrawing Brush="Black">
                        <GeometryDrawing.Geometry>
                            <GeometryGroup>
                                <RectangleGeometry Rect="0,0,50,50" />
                                <RectangleGeometry Rect="50,50,50,50" />
                            </GeometryGroup>
                        </GeometryDrawing.Geometry>
                    </GeometryDrawing>
                </DrawingGroup>
            </DrawingBrush.Drawing>
        </DrawingBrush>
    </Border.BorderBrush>
    <TextBlock Text="Border Content!" Margin="5"/>
</Border>

For GridSplitter:

<Style x:Key="GridSplitterStyle1" TargetType="{x:Type GridSplitter}">
    <Setter Property="Background" Value="Yellow"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type GridSplitter}">
                <Border BorderThickness="1,1,1,1">
                    <Border.BorderBrush>
                        <DrawingBrush Viewport="0,0,8,8" ViewportUnits="Absolute" TileMode="Tile">
                            <DrawingBrush.Drawing>
                                <DrawingGroup>
                                    <GeometryDrawing Brush="Red">
                                        <GeometryDrawing.Geometry>
                                            <GeometryGroup>
                                                <RectangleGeometry Rect="0,0,50,50" />
                                                <RectangleGeometry Rect="50,50,50,50" />
                                            </GeometryGroup>
                                        </GeometryDrawing.Geometry>
                                    </GeometryDrawing>
                                </DrawingGroup>
                            </DrawingBrush.Drawing>
                        </DrawingBrush>
                    </Border.BorderBrush>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>