Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF XAML - Adding multiple styles to resource dictionary which target rowdefinition
    primarykey
    data
    text
    <p>Thanks for your thoughts in helping a relative beginner understand WPF.</p> <p>I am trying to use the following style template in an XAML file for a WPF application:</p> <pre><code>&lt;Window.Resources&gt; &lt;ResourceDictionary&gt; &lt;ResourceDictionary.MergedDictionaries&gt; &lt;ResourceDictionary&gt; &lt;Style TargetType="{x:Type RowDefinition}" x:Key="hideIfNotDischarged"&gt; &lt;Style.Triggers&gt; &lt;DataTrigger Binding="{Binding DischargedBy28Days, Mode=OneWay}" Value="false"&gt; &lt;Setter Property="Height" Value="0" /&gt; &lt;/DataTrigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;Style TargetType="{x:Type RowDefinition}" x:Key="hideIfOutcomeKnownAndAlive"&gt; &lt;Style.Triggers&gt; &lt;DataTrigger Binding="{Binding IsKnownDead, Mode=OneWay}" Value="false"&gt; &lt;Setter Property="Height" Value="0" /&gt; &lt;/DataTrigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/ResourceDictionary&gt; &lt;/ResourceDictionary.MergedDictionaries&gt; &lt;/ResourceDictionary&gt; &lt;/Window.Resources&gt; </code></pre> <p>which will be later used in a grid like so:</p> <pre><code>&lt;Grid&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;RowDefinition Height="30" /&gt; &lt;RowDefinition Style="{StaticResource hideIfNotDischarged}" /&gt; ... </code></pre> <p>However, if there is more than 1 style element targeting Type RowDefinition AND ALSO the ResourceDictionary is nested within a MergedDictionary (even with only a single child ResourceDictionary to merge) the application fails with</p> <p>System.Windows.ResourceDictionary.DeferrableContent: Item has already been added</p> <p>That is, despite the fact the 2 styles have different keys, the resource dictionary is trying to add a dictionary item with name based purely on the target type (and ignoring the key).</p> <p>Any help with how I might overcome this would be most appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload