WPF ItemsControl

Love WPF!  Now need to create a UserControl that shows a horizontal sequence of other UserControl.

Turns out you have to use ItemsControl for this:

  • Laurent Bugnion post at http://www.galasoft.ch/mydotnet/articles/article-2007041201.aspx got me started, but in that examples his ItemsSource is ”{Binding ElementName=mainWindow, Path=DataItems}” with DataItems being an ObservableCollection<MyData> with MyData deriving from DependencyObject. This part is not what I needed.
  • Surf4Fun post filled in the gap: MyData can just be any UserControl that I have created previously. On that post, Surf4Fun uses a static resource for the binding, “{Binding Source={StaticResource dataList}}”, with dataList the key to a static resource of type MyData, and MyData is ObservableCollection<MyUserControl>.
The end solution is to combine the two; this allows to make MyData an ObservableCollection<UserControl> property of my UserControl, so no need for static resources.
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.