我正在使用WPF数据网格来显示数据。我试图弄清楚如何在单击项目时突出显示整个行,如果末尾有空白空间(我正在使用动态生成的列),则包括空白列/空间。请注意,我不想突出显示特定的单元格。这是我看到的http://imgur.com/7Xjoj2H。该行末尾的未使用空间是当前不存在列的空间,并且未突出显示。我希望在点击该行时突出显示该空间。我试过了:WPF DataGrid突出显示整行
将宽度设置为自动的最后一列以填充剩余空间。这对我不起作用,因为这样做会禁用水平滚动条,因为我使用的是动态创建的列,所以我需要该滚动条。
我也尝试添加了DataGridRows风格:
<Trigger Property="IsSelected"
Value="true">
<Setter Property="Background"
Value="{StaticResource SelectedBrush}" />
</Trigger>
这类作品,虽然,在DataGrid负载,或者当我的程序是没有焦点,它看起来像这样:http://imgur.com/EtTmBbH哪里只有未使用空间的最后一个区域被突出显示。
如果可能的话,我宁愿不要通过在结尾添加一个空白虚拟列来解决此问题,因为这会导致与将最后一列宽度设置为自动以上相同的问题。
有什么建议吗?
编辑:
下面是DataGridRow样式代码:
<Style TargetType="{x:Type DataGridRow}"
x:Key="DataGridRowStyle">
<Setter Property="Background"
Value="White" />
<Style.Triggers>
<Trigger Property="AlternationIndex"
Value="1">
<Setter Property="Background"
Value="#efefef" />
</Trigger>
<Trigger Property="IsMouseOver"
Value="true">
<Setter Property="Background"
Value="{StaticResource RolloverBrush}" />
</Trigger>
<Trigger Property="IsSelected"
Value="true">
<Setter Property="Background"
Value="{StaticResource SelectedBrush}" />
</Trigger>
</Style.Triggers>
</Style>
而选择刷:
<LinearGradientBrush x:Key="SelectedBrush"
StartPoint="0,0"
EndPoint="0,1">
<GradientStop Offset="0"
Color="#3399FF" />
</LinearGradientBrush>
DataGrid的代码:
<DataGrid x:Name="JobListView"
AutoGenerateColumns="False"
ItemsSource="{Binding UnitStatusCollection, Mode=TwoWay}"
CanUserDeleteRows="False"
Style="{StaticResource JobGridViewStyle}"
SelectedIndex="{Binding JobsListViewSelectedIndex, Mode=TwoWay}"
SelectedItem="{Binding JobsListViewSelectedUnitStatusPair}"
Utility:DataGridColumnsBehavior.BindableColumns="{Binding DataGridColumns}"
ContextMenu="{StaticResource ListViewContextMenu}"
Margin="10,0"
Grid.Row="1"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
RowStyle="{StaticResource DataGridRowStyle}"
AlternationCount="2"
HorizontalGridLinesBrush="#5A5A5F"
VerticalGridLinesBrush="#5A5A5F">
你可以显示“DataGridRows”的'Style'标签吗? –
编辑该帖子以显示它 – KSF
你如何将它应用到网格?您的代码适用于DataGrid上的'RowStyle =“{StaticResource DataGridRowStyle}”'。 –