Thanks for your thoughts in helping a relative beginner understand WPF.
I am trying to use the following style template in an XAML file for a WPF application:
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<Style TargetType="{x:Type RowDefinition}"
x:Key="hideIfNotDischarged">
<Style.Triggers>
<DataTrigger Binding="{Binding DischargedBy28Days,
Mode=OneWay}" Value="false">
<Setter Property="Height" Value="0" />
</DataTrigger>
</Style.Triggers>
</Style>
<Style TargetType="{x:Type RowDefinition}"
x:Key="hideIfOutcomeKnownAndAlive">
<Style.Triggers>
<DataTrigger Binding="{Binding IsKnownDead,
Mode=OneWay}" Value="false">
<Setter Property="Height" Value="0" />
</DataTrigger>
</Style.Triggers>
</Style>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
Which will be later used in a grid like so:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="30" />
<RowDefinition Style="{StaticResource hideIfNotDischarged}" />
...
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
System.Windows.ResourceDictionary.DeferrableContent: Item has already been added.
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).
Any help with how I might overcome this would be most appreciated.
RowDefinitionstyles in your application as long as they have a unique key, I just copied the 2 style you have above into a ResourceDictionary and it compiled fine and both styles can be applied, I think you have another set of these styles somewhere or VS is having a caching issue, try clean and rebuilding the solution - sa_ddam213x:keybefore theTargetTypeto avoid theResourceDictionarychecking theTargetTypeexists before it realizes it has ax:Key- sa_ddam213