views:

39

answers:

1

I want to define something like this

<myCustomControl>
  <myCustomControl.Images>
     <Image
        Source="{StaticResource LockedIcon16}" />
     <Image
        Source="{StaticResource UnlockedIcon16}"/>
  <myCustomControl.Images>
<myCustomControl/>

what property definitions do i need to get that collection (Images) happening?

A: 

System.Windows.Controls.Image should do it.

Haven't tested it, but it should work.

public class myCustomControl {
  //...
    public ObservableCollection<Image> Images {
        get { return (ObservableCollection<Image>)GetValue(ImagesProperty); }
        set { SetValue(ImagesProperty, value); }
    }

    // Using a DependencyProperty as the backing store for Images.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty ImagesProperty =
        DependencyProperty.Register("Images", typeof(ObservableCollection<Image>), typeof(myCustomControl), new PropertyMetadata(null));
}
Igor Zevaka
Just an Image, or do you mean an *array* or *List* (IEnumerable) of Image?
slugster
`List<Image>` is the easiest to do. Haven't tried with arrays, not sure if it'll work.
Igor Zevaka
works but it has to be a dependency property.
Aran Mulholland
Interesting, I'll update the answer.
Igor Zevaka
i was wrong about this, it doesnt have to be a dependency property, the collection just has to be instantiated before use
Aran Mulholland