C# MVVM:将ContentControl绑定到复选框

C# MVVM:将ContentControl绑定到复选框,c#,wpf,mvvm,C#,Wpf,Mvvm,我有一个ContentControl,我想将它的Content属性绑定到复选框的IsChecked属性。 我正在使用MVVM,我想这样做: <ContentControl ContentTemplate="{Binding CurrentTemplate}"/> <CheckBox IsChecked="{Binding IsNewCustumor}"/> 在视图模型中,我会监听IsNewCustumor属性的变化,并将相应的DataTemplate分配给Curre

我有一个
ContentControl
,我想将它的
Content
属性绑定到
复选框的
IsChecked
属性。 我正在使用MVVM,我想这样做:

<ContentControl ContentTemplate="{Binding CurrentTemplate}"/>
<CheckBox IsChecked="{Binding IsNewCustumor}"/>

在视图模型中,我会监听
IsNewCustumor
属性的变化,并将相应的
DataTemplate
分配给
CurrentTemplate
属性,但我认为这将涉及在视图模型中使用视图,而视图模型不是
MVVM
。 另一个想法是编写一个转换器类,我不知道该如何具体实现它


有人能帮忙吗?

据我所知,您希望根据属性
IsNewCustomer
的值切换模板。实现这一点的一种方法是使用样式触发器。优点是,它纯粹是XAML,易于阅读:

<ContentControl>
    <ContentControl.Style>
        <Style TargetType="ContentControl>
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsNewCustomer}" Value="True">
                    <Setter Property="ContentTemplate" Value="Set the template for new customers here">
                </DataTrigger>
            </Style.Triggers>
         <Setter Property="ContentTemplate" Value="Set the template for not new customers here">
        </Style>
    <ContentControl.Style>
<ContentControl>


令人印象深刻的思维方式。谢谢,我添加了一些修改,因为我想直接绑定到复选框。谢谢。