I know this is an ancient question, but I decided to add my answer anyway. After a lot of experimentation, it seems that the following works perfectly for a 1 pixel Gridsplitter
<ControlTemplate x:Key="gs0" TargetType="{x:Type GridSplitter}"> <Border Margin="-5,0" Background="Transparent"> <TextBlock Width="1" Background="Green" /> </Border> </ControlTemplate>
Verified with the following code:
Grid HorizontalAlignment="Left" > <Grid.ColumnDefinitions> <ColumnDefinition Width="200"/> <ColumnDefinition Width="1"/> <ColumnDefinition Width="200"/> </Grid.ColumnDefinitions> <Grid Grid.Column="0"> .... </Grid> <GridSplitter Grid.Column="1" HorizontalAlignment="Stretch" Template ="{StaticResource gs0}"/>
Without a template, the mouse capture area is 1 pixel. But, as indicated above, with the template, it is increased to 7 pixels, which is something like this. The same code can be adjusted for a line with a width of 2 or more pixels by setting Textblock Width , Border Margin and ColumnDefinition Width . You can make the mouse capture ridiculously huge, but the problem is that the zoom only happens on the left side; it does not center on the line, which becomes more noticeable the more you increase it. But for a narrow line, this is an easy way to increase mouse capture to something useful.
I use Gridsplitters with a width of 2 pixels and use the style to set IsMouseOver properties, for example:
<Style TargetType="{x:Type GridSplitter}"> <Setter Property="HorizontalAlignment" Value="Stretch"/> <Setter Property="Background" Value="LightGray"/> <Setter Property="OpacityMask" Value="{StaticResource gs_OpacityMask}"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type GridSplitter}"> <Border Margin="-3,0" Background="Transparent"> <TextBlock x:Name="tb" Width="2" Background="{TemplateBinding Background}" /> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" TargetName="tb" Value="#FF0B75FD" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style>
IMPORTANT: ColumnDefinition Width must be set to 3 or 4 in this case for a line 2 pixels wide.
source share