In a Wpf DataGrid, each row has a blank area that grows to fill the remaining space. I imagine this area is more appropriately called a "gutter", but I actually don't know the proper terminology for it. I like having this, but I noticed a problem with it. If I click on the blank area, it does not seem to process the IsSelected
trigger that I have set on the Row. However, the IsMouseOver
trigger is fired. Very strange. Here is a picture demonstrating the area that I have mentioned:
And here is the segment of Xaml that I think will be required to fix this. If more is needed, just tell me and I will post it.
<!-- Style and template for the DataGridRow. -->
<Style x:Key="VoidwalkerDataGridRowStyle" TargetType="{x:Type DataGridRow}">
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="Validation.ErrorTemplate" Value="{x:Null}" />
<Setter Property="ValidationErrorTemplate">
<Setter.Value>
<ControlTemplate>
<TextBlock
Margin="2,0,0,0"
VerticalAlignment="Center"
Foreground="Red"
Text="!" />
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridRow}">
<Border
x:Name="DGR_Border"
Background="{DynamicResource VoidwalkerContextBrush}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
SnapsToDevicePixels="True">
<SelectiveScrollingGrid>
<SelectiveScrollingGrid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</SelectiveScrollingGrid.ColumnDefinitions>
<SelectiveScrollingGrid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</SelectiveScrollingGrid.RowDefinitions>
<DataGridCellsPresenter
Grid.Column="1"
ItemsPanel="{TemplateBinding ItemsPanel}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
<DataGridDetailsPresenter
Grid.Row="1"
Grid.Column="1"
SelectiveScrollingGrid.SelectiveScrollingOrientation="{Binding AreRowDetailsFrozen, ConverterParameter={x:Static SelectiveScrollingOrientation.Vertical}, Converter={x:Static DataGrid.RowDetailsScrollingConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"
Visibility="{TemplateBinding DetailsVisibility}" />
<DataGridRowHeader
Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="0"
SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical"
Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.Row}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" />
</SelectiveScrollingGrid>
</Border>
<ControlTemplate.Triggers>
<!--
Alternation Coloration Triggers
-->
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter Property="Foreground" Value="{DynamicResource VoidwalkerForegroundBrush}" />
<Setter TargetName="DGR_Border" Property="Background" Value="{DynamicResource VoidwalkerContextBrush}" />
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Foreground" Value="{DynamicResource VoidwalkerForegroundBrush}" />
<Setter TargetName="DGR_Border" Property="Background" Value="{DynamicResource VoidwalkerControlBrush}" />
</Trigger>
<!--
Is Selected Triggers
-->
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="DGR_Border" Property="BorderBrush" Value="{DynamicResource VoidwalkerBorderBrush}" />
<Setter TargetName="DGR_Border" Property="Background" Value="{DynamicResource VoidwalkerBorderBrush}" />
</Trigger>
<!--
Is Mouse Over Triggers
-->
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="DGR_Border" Property="BorderBrush" Value="{DynamicResource VoidwalkerBorderBrush}" />
<Setter TargetName="DGR_Border" Property="Background" Value="{DynamicResource VoidwalkerBorderBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Just to clarify my question even further:
When I click on the "Gutter" area in the picture, my IsSelected
trigger is not fired. If I click on any cell to the left of it, that row will be selected. The strange thing is that my other IsMouseOver
trigger is still fired when mousing over the gutter area. Is there a way that I can emulate the IsSelected
behavior on the gutter area for the row it is on?
It's only the actual cells that are selectable. You can easily make the "gutter" selectable by simply adding another blank column to your DataGrid
:
<DataGrid.Columns>
...
<DataGridTemplateColumn Width="*" />
</DataGrid.Columns>
Or make the last existing column stretch horizontally by setting its Width
to *
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.