Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing a List<UIElement> as the ItemsSource for an ItemsControl causes the DataTemplate not to be applied
    primarykey
    data
    text
    <p>I have created a custom panel (MyCustomControl) that can contain other controls and be configurable through dependency properties. Inside a different user control (MyUserControl), I have multiple instances of MyCustomControl configured in XAML. </p> <p>Outside of the user control, I am trying to bind an ItemsControl (myItemsControl) to the list of MyCustomControls that exist in MyUserControl at run-time. Therefore, I have exposed the List from MyUserControl through a dependency property.</p> <p>I am experiencing unexpected behavior from this strategy. I would like the ItemsControl to take the List and use each control instance inside as an object with data values that can fill in the ItemsControl's DataTemplate. However, it is not doing that. Instead, it is basically ignoring the DataTemplate altogether, and simply re-rendering all the controls that are in the list/ItemsSource.</p> <p>In summary, if I use a list of controls as an ItemsSource for an ItemsControl, it does not use them as data objects but instead renders them as control instances.</p> <p>Surprisingly, if I attempt to do the same thing but use a ListBox instead of an ItemsControl, the databinding works as expected. I do not want to use a ListBox for other reasons. Does anyone know what the difference is between a ListBox and an ItemsControl that affects this behavior?</p> <p>Edit: I've found another user who's had the same issue with no listed resolution here: <a href="http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/d0942de0-7bcf-41b9-9003-ca244bf80206/" rel="nofollow noreferrer">msdn social forum post</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload