Technology is not science. RSS Feed


UserControl in DataTemplate must be in a Panel

While investigating MVVM in Silverlight 2, I came across a problem putting a UserControl in a DataTemplate used by an ItemsControl. I started with the following XAML for the DataTemplate used by my ItemsControl in the page.

<UserControl.Resources>
<DataTemplate x:Key="ListDataTemplate">
<a:DetailControl DataContext="{Binding}" />
</
DataTemplate>
</
UserControl.Resources>

I don't know why but the data didn't bind correctly in my DetailControl so for every row in the data bound to the list control I ended up with user controls in my list that had no data. Wrapping the user control in a Grid in the DataTemplate corrected the problem.

<UserControl.Resources>
<DataTemplate x:Key="ListDataTemplate">
<Grid>
<!-- Data-binding fails if I don't wrap it in a panel. -->
<a:DetailControl DataContext="{Binding}" />
</
Grid>
</
DataTemplate>
</
UserControl.Resources>
 
Posted by Chris Idzerda | 0 Comments | Trackback Url | Bookmark with:        
Tags: Work

Links to this Post

Comments

Name:
URL:
Email:
Comments:

CAPTCHA Image Validation