2012-05-04 60 views
6

Tôi có một DataGrid được định nghĩa như sau. Khi tôi bấm vào một ô trong DataGrid chỉ ô được đánh dấu. Làm thế nào tôi có thể thay đổi nó để khi tôi nhấp vào ô, toàn bộ hàng được tô đậm?Làm cách nào để có thể tô sáng toàn bộ hàng DataGrid khi một ô được nhấp?

<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> 
+0

tôi đã cố gắng tìm kiếm một tài sản gắn liền với Row các tế bào, nhưng không có bất kỳ. Tất cả những gì tôi có thể tìm thấy là thuộc tính cột. – DaveDev

Trả lời

19

Các bạn đã thử <DataGrid SelectionMode="Single" SelectionUnit="FullRow">?

Nhưng trên thực tế hành vi mặc định của nó nếu tôi bấm vào một tế bào toàn bộ hàng được đánh dấu

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

+0

Cảm ơn bạn - điều này chính xác. Tôi phải đợi 4 phút để chọn câu trả lời đúng. – DaveDev

Các vấn đề liên quan