2

In a WPF application I have an ObservableCollection of objects (areas on an image) that I want to display and edit (size and position) at runtime.

I would like to use an InkCanvas in Select mode with Rectangles representing my objects, but it doesn't seem to directly support data binding.

Is it possible to somehow bind the Children collection of an InkCanvas to an ObservableCollection?

Tiberiu Ana
  • 3,663
  • 1
  • 24
  • 25
  • 1
    I tried to do something similar but couldn't find anything obvious. Ended up using an attached dependency property to manually sync the Children collection and the ObservableCollection that I wanted to bind to. Would love to hear any better suggestions though – Steve Greatrex Feb 08 '10 at 12:50
  • This is what I am basically doing right now. Besides manually populating the InkCanvas Children, I am also handling SelectionMoved and SelectionResized and manually putting the value back into the model. It all looks to me like one obvious thing for them to enhance in future versions. – Tiberiu Ana Feb 09 '10 at 12:19

1 Answers1

1

Have you tried using a ItemsControl with a Canvas set as ItemsControl.ItemsPanel? Then you can bind the ItemsSource property to your ObservableCollection. You can then use a ItemsControl.ItemsTemplate to bind a property of an item to the Canvas.Left (Right) Properties for absolute placement.

Markus Hütter
  • 7,796
  • 1
  • 36
  • 63
  • But then you wouldn't be able to select those Children of the InkCanvas with EditingMode.Selection. If it's readonly, this is an adequate solution, but it's not a general InkCanvas solution. – Chris Hagan Nov 08 '11 at 00:04