I have a UserControl with the following Property:
public List<Rect> HotSpots
{
get { return (List<Rect>)GetValue(HotSpotsProperty); }
set { SetValue(HotSpotsProperty, value); }
}
public static readonly DependencyProperty HotSpotsProperty =
DependencyProperty.Register("HotSpots", typeof(List<Rect>), typeof(ImageViewPort), new FrameworkPropertyMetadata(HotSpotsChanged));
Since compiled XAML (XAML 2006 by default) doesn’t support generics the way the 2009 specification allows, I wonder is there any chance of doing something like the following:
<WPF:ImageViewPort Grid.Row="1">
<WPF:ImageViewPort.HotSpots>
<Rect Location="0,0" Height="30" Width="50"></Rect>
<Rect Location="10,35" Height="30" Width="20"></Rect>
</WPF:ImageViewPort.HotSpots>
</WPF:ImageViewPort>
Or is my only chance a Binding like the following?
<WPF:ImageViewPort Grid.Row="1" HotSpots="{Binding Path=HotSpots}"/>
Just out of curiosity, the limitation seems to be XAML’s support for generics, so writing a List derivate should do the trick, shouldn’t it?
Since XAML isn’t used to add to Collections but rather to setting them, I’ve had to create a wrapping XAML Node that initializes the Collection. Since the Collection is generic, I can’t do this as it is, but have to create a wrapper like so :
In my XAML then, I can set it like so:
Easy enough, once you’ve seen it work =)