C# 将内容演示者内容绑定到可视元素
我有一个带有items源的items控件,我希望它显示预览C# 将内容演示者内容绑定到可视元素,c#,wpf,mvvm,data-binding,C#,Wpf,Mvvm,Data Binding,我有一个带有items源的items控件,我希望它显示预览 <ItemsControl ItemsSource="{Binding Path=Children}"> <ItemsControl.ItemTemplate> <DataTemplate> <ContentControl> <Con
<ItemsControl ItemsSource="{Binding Path=Children}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<ContentControl>
<ContentControl.ContentTemplate>
<DataTemplate>
<ContentPresenter Content="{Binding Preview}"/>
</DataTemplate>
</ContentControl.ContentTemplate>
</ContentControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
但它似乎没有呈现任何东西,我缺少什么?像这样尝试
<ItemsControl ItemsSource="{Binding Children}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<ContentPresenter Content="{Binding Preview}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
或
没有datacontext,因此它没有显示任何内容。在视图模型中创建UI元素不是MVVM。
<ItemsControl ItemsSource="{Binding Children}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<ContentPresenter Content="{Binding Preview}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<ItemsControl ItemsSource="{Binding Path=Children}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<ContentControl Content="{Binding}">
<ContentControl.ContentTemplate>
<DataTemplate>
<ContentPresenter Content="{Binding Preview}"/>
</DataTemplate>
</ContentControl.ContentTemplate>
</ContentControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>