【发布时间】:2016-12-15 22:20:34
【问题描述】:
我有一个带有项目源的项目控件,我希望它显示预览
<ItemsControl ItemsSource="{Binding Path=Children}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<ContentControl>
<ContentControl.ContentTemplate>
<DataTemplate>
<ContentPresenter Content="{Binding Preview}"/>
</DataTemplate>
</ContentControl.ContentTemplate>
</ContentControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
预览是一个网格
public class Child
{
public Grid Preview { get; set; }
public Child()
{
Preview = new Grid();
Preview.Children.Add(new TextBlock() { Text = "Test"});
Preview.Background = new SolidColorBrush(Colors.Red);
}
}
但它似乎没有渲染任何东西,我错过了什么?
【问题讨论】:
-
在视图模型中创建 UI 元素不是 MVVM。
标签: c# wpf mvvm data-binding