2012-01-24 63 views
2

我想基於dataTrigger更改AlternatingRowBackground顏色。 我收到來自IDE的錯誤,它不會生成(請參閱下面的xaml)。在觸發器上設置Wpf AlternatingRowBackground

錯誤:找不到樣式屬性的類型「AlternatingRowBackground 'System.Windows.Controls.DataGridRow'

的XAML

<Style TargetType="{x:Type DataGridRow}"> 
      <Setter Property="AlternatingRowBackground" Value="Beige" /> 
      <Style.Triggers> 
       <Trigger Property="IsMouseOver" Value="True"> 
        <Setter Property="Background" Value="{StaticResource SelectedRowBackgroundBrush}" /> 
       </Trigger> 
       <DataTrigger Binding="{Binding BondType}" Value="P"> 
        <Setter Property="Background" Value="Pink"/> 
        <Setter Property="AlternatingRowBackground" Value="LightPink" /> 
       </DataTrigger> 
      </Style.Triggers> 
     </Style> 

任何想法,將不勝感激。

回答

3

你的風格更是瞄準了DataGridRow,但 「AlternatingRowBackground」 是的DataGrid的屬性。

因此,您需要DataGrid和DataGridRow的單獨樣式。設置您的DataGrid風格的AlternatingRowBackground:

<Style x:Key="DataGridStyle" TargetType="{x:Type DataGrid}"> 
    <Setter Property="AlternatingRowBackground" Value="Beige" /> 
    ... 
</Style> 

<Style x:Key="DataGridDemoRowStyle" TargetType="{x:Type DataGridRow}"> 
    <Style.Triggers> 
      <Trigger Property="IsMouseOver" Value="True"> 
       <Setter Property="Background" Value="{StaticResource SelectedRowBackgroundBrush}" /> 
      </Trigger> 
      <DataTrigger Binding="{Binding BondType}" Value="P"> 
       <Setter Property="Background" Value="Pink"/> 
      </DataTrigger> 
    </Style.Triggers> 
</Style> 
+0

謝謝我會試一試,回到你身邊,有道理。 – DermFrench

+0

嗨,我實際上想要做的是在交替行上應用biege,除非在datatrigger被滿足時,在那個階段我需要lightpink。那可能嗎? – DermFrench

+0

你是說你想要改變交替行的rowRowColor的行在哪裏dataTrigger符合? – theartwebreathe