views:

29

answers:

1

Hi,

I have the following class:

public class MyCustomCanvas : Canvas
{
    public static readonly DependencyProperty SpritesProperty = DependencyProperty.Register(
       "Sprites",
       typeof(ObservableCollection<Sprite>),
       typeof (MyCustomCanvas),
       new FrameworkPropertyMetadata(
           null,
           FrameworkPropertyMetadataOptions.AffectsRender|FrameworkPropertyMetadataOptions.AffectsParentMeasure));

    public ObservableCollection<Sprite> Sprites
 {
     get { return (ObservableCollection<Sprite>) GetValue(SpritesProperty); }
        set { SetValue(SpritesProperty, value); }
 }

The Sprite class implements INotifyPropertyChanged. the Sprites property is bound to some other collection.

What I'm trying to achieve, is that whenever a property changes in a sprite that's in the collection OR whenever I add or remove items in the collection, the canvas redraws itself.

I know I could add a function to each sprite's Property Changed event handler, but I wanted to know if there's a nicer way to do this.

Thanks in advance.

A: 

It might be easier to just use an ItemsControl with it's Panel set to a Canvas.

mdm20
I've found a workaround. The Custom Canvas has a collection of Images whose properties are bound to the sprites. Then, these images are added as children of the canvas.
Mougli