Binding the position and size of a UserControl inside a Canvas in WPF

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2010-03-30T13:11:36Z Indexed on 2010/03/30 13:13 UTC
Read the original article Hit count: 687

Hi. We have dynamically created (i.e. during runtime, via code-behind) UserControls inside a Canvas. We want to bind the position (Canvas.Left and Canvas.Top) and width of those sizable and draggable UserControls to a ObservableCollection<>. How would we achieve this if the Usercontrol is contained in a DataTemplate which in turn is used by a ListBox whose DataContext is set to the collection we want to bind to?

In other words, how do we bind a control's position and size that doesn't exist in XAML, but in code only (because it's created by clicking and dragging the mouse)?

Notice that the collection can be empty or not empty, meaning that the size and position stores in a collection item must be correctly bound to so that the UserControl can be sized and positioned correctly in the Canvas - via DataBinding. Is this possible?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about databinding