WPF: How to Style Vertical GridSplitter


<Window x:Class="VerticalGridSplitterExample"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="VerticalGridSplitter Example"
        Height="300" Width="300">
    <Window.Resources>
        
        <Style x:Key="GridSplitterVerticalGripStyle" TargetType="{x:Type GridSplitter}">
            <Setter Property="VerticalAlignment" Value="Stretch" />
            <Setter Property="FocusVisualStyle" Value="{x:Null}" />
            <Setter Property="Cursor" Value="SizeWE" />
            <Setter Property="FocusVisualStyle" Value="{x:Null}" />
            <Setter Property="Background"
                    Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type GridSplitter}">
                        <Border BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                Background="{TemplateBinding Background}"
                                Width="{TemplateBinding Width}">
                            <Border Height="50" Width="4" VerticalAlignment="Center"
                                    HorizontalAlignment="Center" BorderThickness="1 0"
                                    Background="White" BorderBrush="#A0A0A0">
                            </Border>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
 
        <Style x:Key="VerticalGridSplitter" TargetType="{x:Type GridSplitter}"
                BasedOn="{StaticResource GridSplitterVerticalGripStyle}">
            <Setter Property="Width" Value="6" />
            <Setter Property="Margin" Value="15 0" />
            <Setter Property="VerticalAlignment" Value="Stretch" />
            <Setter Property="HorizontalAlignment" Value="Center" />
        </Style>
    </Window.Resources>
    
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid>
            <Border Background="LightBlue" />
        </Grid>
        <GridSplitter Grid.Column="1" Style="{StaticResource VerticalGridSplitter}" />
        <Grid Grid.Column="2">
            <Border Background="LightBlue" />
        </Grid>
    </Grid>
</Window>

Comments

Popular posts from this blog

WPF How to Dispose ViewModel when the associated UserControl (Not Window) closes?

C# How to unit test Dispatcher

WPF: How to Deep Copy WPF object (e.g. UIElement) ?