2016-12-01 106 views
1

我有一個包含以下內容的資源字典:與同WPF靜態資源:具有相同鍵的項已被添加

<SolidColorBrush x:Key="RowAlt" 
        Color="Gray" /> 
<Style x:Key="MainTreeRowStyle" 
      TargetType="{x:Type dxg:RowControl}"> 
     <Setter Property="Foreground" 
       Value="White" /> 
     <Setter Property="ShowHorizontalLine" 
       Value="False" /> 
     <Setter Property="ShowVerticalLines" 
       Value="False" /> 
     <Style.Triggers> 
      <MultiDataTrigger> 
       <MultiDataTrigger.Conditions> 
        <Condition Binding="{Binding AlternateRow}" 
           Value="False" /> 
       </MultiDataTrigger.Conditions> 
       <Setter Property="Background" 
         Value="Black" /> 
      </MultiDataTrigger> 
      <Trigger Property="dxg:GridViewBase.IsFocusedRow" 
        Value="True"> 
       <Setter Property="Background" 
         Value="{StaticResource RowAlt}" /> 
      </Trigger> 
     </Style.Triggers> 
</Style> 

以上是拋出一個異常

「的項目密鑰已被添加。「

如果我

<Setter Property="Background" 
          Value="{DynamicResource RowAlt}" /> 

更換

<Setter Property="Background" 
          Value="{StaticResource RowAlt}" /> 

沒有拋出異常。爲什麼是這樣?

回答

0

StaticResource和DynamicResource之間的區別在於如何通過引用元素檢索資源。 StaticResource只被引用元素檢索一次,並用於資源的整個生命週期。另一方面,每次使用引用對象時都會獲取DynamicResource。

+0

好吧,但這並不能解釋爲什麼「」具有相同密鑰的項目已被添加。「拋出異常。 – dman

相關問題