I have a Dependency Property for items on a legend. It looks like:
public List<LegendItem> LegendItems
{
get { return (List<LegendItem>)GetValue(LegendItemsProperty); }
set { SetValue(LegendItemsProperty, value); }
}
// Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
public static readonly DependencyProperty LegendItemsProperty =
DependencyProperty.Register("LegendItems", typeof(List<LegendItem>), typeof(TipScoreboard), new PropertyMetadata());
where LegendItem
is a UserControl
.
I am able to set it in XAML like this with no problem.
<local:TipScoreboard.LegendItems>
<local:LegendItem ItemFillBrush="{DynamicResource GreenStatusBrush}"
Label="{x:Static res:TipLabels.GoodScan}"/>
<local:LegendItem ItemFillBrush="{DynamicResource RedStatusBrush}"
Label="{x:Static res:TipLabels.BadScan}"/>
</local:TipScoreboard.LegendItems>
However when I go to set this property in a setter like this:
<Setter Property="LegendItems">
<Setter.Value>
<local:LegendItem ItemFillBrush="{DynamicResource GreenStatusBrush}"
Label="{x:Static res:TipLabels.GoodScan}"/>
<local:LegendItem ItemFillBrush="{DynamicResource YellowStatusBrush}"
Label="{x:Static res:TipLabels.LowConfidence}"/>
</Setter.Value>
</Setter>
I get the The property "Value" is set more than once.
for the setter. I'm not sure how to wrap this or what to do. I've tried just wrapping a List around it but that didn't seem to work.
EDIT: I tried created a custom wrapped collection and everything complies and run but the content is blank.
public class LegendItemCollection : Collection<LegendItem>
{
}
public LegendItemCollection LegendItems
{
get { return (LegendItemCollection)GetValue(LegendItemsProperty); }
set { SetValue(LegendItemsProperty, value); }
}
public static readonly DependencyProperty LegendItemsProperty =
DependencyProperty.Register("LegendItems", typeof(LegendItemCollection), typeof(TipScoreboard), new PropertyMetadata());
and the XAML:
<Setter Property="LegendItems">
<Setter.Value>
<local:LegendItemCollection>
<local:LegendItem ItemFillBrush="{DynamicResource GreenStatusBrush}"
Label="{x:Static res:TipLabels.GoodScan}"/>
<local:LegendItem ItemFillBrush="{DynamicResource YellowStatusBrush}"
Label="{x:Static res:TipLabels.LowConfidence}"/>
</local:LegendItemCollection>
</Setter.Value>
</Setter>