c# - 单击单个单元格时如何突出显示整个 DataGrid 行?

标签 c# wpf xaml datagrid

我有一个 DataGrid 定义如下。当我单击 DataGrid 中的一个单元格时,只有该单元格突出显示。如何更改它以便在我单击单元格时突出显示整行?

<DataGrid Name="fileGrid" AutoGenerateColumns="False" Height="150" Width="Auto" 
            Margin="10,10,0,0" 
            HorizontalAlignment="Left" VerticalAlignment="Top" SelectionChanged="fileGrid_SelectionChanged">
    <DataGrid.Columns>
        <DataGridTextColumn Header="Company Name" 
            x:Name="columnCompanyName" 
            Binding="{Binding Path=Customer.CompanyName}"
            IsReadOnly="True">                    
        </DataGridTextColumn>

        <DataGridTextColumn Header="Customer Surname" 
            x:Name="columnCustomerSurname" 
            Binding="{Binding Path=Customer.Surname}"
            IsReadOnly="True">
        </DataGridTextColumn>

        <DataGridTextColumn Header="Customer Address" 
            x:Name="columnAddressLine1" 
            Binding="{Binding Path=Customer.Address.Line1}"
            IsReadOnly="True">
        </DataGridTextColumn>

        <DataGridTextColumn Header="Customer City" 
            x:Name="columnCity" 
            Binding="{Binding Path=Customer.Address.City}"
            IsReadOnly="True">
        </DataGridTextColumn>

    </DataGrid.Columns>
</DataGrid>

最佳答案

你试过了吗<DataGrid SelectionMode="Single" SelectionUnit="FullRow">

但实际上这是默认行为,如果我单击一个单元格,整行都会突出显示

选择模式文档:https://msdn.microsoft.com/en-us/library/system.windows.controls.datagridselectionmode%28v=vs.110%29.aspx

选择单元文档:https://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.selectionunit%28v=vs.110%29.aspx

关于c# - 单击单个单元格时如何突出显示整个 DataGrid 行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10447152/

相关文章:

wpf - 根据 View 模型中的更改更新依赖属性

c# - 只读依赖属性更新但首次使用时不起作用

wpf - ComboBox 的自定义模板忽略 DisplayMemberPath 的使用

c# - 将位图保存到流中

c# - 在数据表中导入数据行

C# 相当于 Javascript "push"

c# - 使用共享服务的示例。 Prism

c# - [名称]View.xaml.cs 文件中应该包含哪些内容?

c# - XAML intellisense 不适用于 <StaticResource/>

c# - Xamarin ios 可达性不起作用