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

时间:2012-05-04 10:34:32

标签: 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>

2 个答案:

答案 0 :(得分:22)

您是否尝试过<DataGrid SelectionMode="Single" SelectionUnit="FullRow">

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

SelectionMode doc:https://msdn.microsoft.com/en-us/library/system.windows.controls.datagridselectionmode%28v=vs.110%29.aspx

SelectionUnit doc:https://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.selectionunit%28v=vs.110%29.aspx

答案 1 :(得分:-1)