【发布时间】:2011-11-22 15:49:09
【问题描述】:
在 Silverlight 中,我有一个 DataTemplate,它绑定到一个对象,该对象包含一个拥有 UserControl 的属性。
在 DataTemplate 中,我想绑定到保存 UserControl 的属性,以便 UserControl 显示为 DataTemplate 的一部分。
目前,我正在使用 ItemsControl 并将 ItemsSource 绑定到包含 UserControl 的属性,这正在工作,但是,UserControl 没有填充可用空间,这让我想知道是否有更好的方法这样做。
感谢您的帮助。
马丁。
编辑:根据要求提供一些 XAML:
<DataTemplate x:Key="ContentTemplate">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<TextBlock Text="Large Content" Grid.Row="0"/>
<ItemsControl ItemsSource="{Binding Contents}" Grid.Row="1" MinHeight="200" MinWidth="300" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
</Grid>
</DataTemplate>
其中,绑定的Contents属性如下:
private UserControl _contents;
public UserControl Contents
{
get {return _contents;}
set
{
_contents = value;
NotifyPropertyChanged("Contents");
}
}
【问题讨论】:
-
你能提供更多细节(Xaml)吗?它在答案中提供了相关示例。谢谢。
-
按要求完成。感谢您的关注。
标签: silverlight data-binding binding mvvm datatemplate