2014-01-24 60 views
1

我有一個datagrid,我正在執行文本搜索。當搜索確定該行是否要強調,我在底層的對象指定一個布爾值「真」,而在我的WPF XML我有以下幾點:如何使選定的行在未聚焦的數據網格中突出顯示?

 <DataGrid.Style> 
      <Style TargetType="DataGrid"> 
       <Setter Property="AlternatingRowBackground" Value="LightGray"/> 
      </Style> 
     </DataGrid.Style> 
     <DataGrid.RowStyle> 
      <Style TargetType="DataGridRow"> 
       <Style.Triggers> 
        <DataTrigger Binding="{Binding Highlighted, Mode=TwoWay}" Value="True"> 
         <Setter Property="Background" Value="Yellow" /> 
        </DataTrigger> 
       </Style.Triggers> 
      </Style> 
     </DataGrid.RowStyle> 

注意「綁定白標明」;這就是行被突出顯示的方式。這似乎工作正常,除非在數據網格中選擇了一行。發生這種情況時,當數據網格失去焦點時,所選行將變爲灰色。當數據網格失去焦點時,如何指定SELECTED ROW的行顏色(意思是「高亮顯示」爲真),以便仍然顯示黃色(可能會更暗,因此很明顯它已被選中)?

回答

0

試試這個:

  <DataGrid.Style> 
      <Style TargetType="DataGrid"> 
       <Setter Property="AlternatingRowBackground" Value="LightGray"/> 
      </Style> 
     </DataGrid.Style> 
     <DataGrid.RowStyle> 
      <Style TargetType="DataGridRow"> 
       <Style.Triggers> 
        <DataTrigger Binding="{Binding Highlight}" Value="True"> 
         <Setter Property="Background" Value="Yellow" /> 
        </DataTrigger> 
        <Trigger Property="IsSelected" Value="True"> 
         <Setter Property="Background" Value="#FF3CF1C8" /> 
         <Setter Property="BorderBrush" Value="#FF3CF1C8" /> 
        </Trigger> 
        <MultiDataTrigger> 
         <MultiDataTrigger.Conditions> 
          <Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Mode=Self}}" Value="True"/> 
          <Condition Binding="{Binding Highlight}" Value="True"/> 
         </MultiDataTrigger.Conditions> 
         <Setter Property="Background" Value="#FFFBAE8A" /> 
         <Setter Property="BorderBrush" Value="#FFFBAE8A" /> 
        </MultiDataTrigger> 
       </Style.Triggers> 
      </Style> 
     </DataGrid.RowStyle> 
     <DataGrid.CellStyle> 
      <Style TargetType="DataGridCell"> 
       <Style.Triggers> 
        <Trigger Property="IsSelected" Value="True"> 
         <Setter Property="Background" Value="#FF3CF1C8" /> 
         <Setter Property="BorderBrush" Value="#FF3CF1C8" /> 
        </Trigger> 
        <MultiDataTrigger> 
         <MultiDataTrigger.Conditions> 
          <Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGridRow}}}" Value="True"/> 
          <Condition Binding="{Binding Highlight}" Value="True"/> 
         </MultiDataTrigger.Conditions> 
         <Setter Property="Background" Value="#FFFBAE8A" /> 
         <Setter Property="BorderBrush" Value="#FFFBAE8A" /> 
        </MultiDataTrigger> 
       </Style.Triggers> 
      </Style> 
     </DataGrid.CellStyle> 

它保持在選定的情況下選定行DataGrid中失去的焦點和突出顯示的行得到了不同的選擇顏色的時候已經失去焦點,其也保持。

相關問題