Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将内容演示者内容绑定到可视元素_C#_Wpf_Mvvm_Data Binding - Fatal编程技术网

C# 将内容演示者内容绑定到可视元素

C# 将内容演示者内容绑定到可视元素,c#,wpf,mvvm,data-binding,C#,Wpf,Mvvm,Data Binding,我有一个带有items源的items控件,我希望它显示预览 <ItemsControl ItemsSource="{Binding Path=Children}"> <ItemsControl.ItemTemplate> <DataTemplate> <ContentControl> <Con

我有一个带有items源的items控件,我希望它显示预览

<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>