C# 是否可以将Xaml中的内容绑定到代码中的网格

C# 是否可以将Xaml中的内容绑定到代码中的网格,c#,xaml,binding,grid,contentpresenter,C#,Xaml,Binding,Grid,Contentpresenter,我知道这是一种不好的做法,但我已经在代码中创建了一个网格,并希望将该网格绑定到我的视图 到目前为止,我已经: 视图: 但从未输入Get方法。我做错了什么?我的错。。该方法在我的情况下工作,只是绑定不正确 System.Windows.Data错误:40:BindingExpression路径错误: 在“对象”上未找到“CustomerTagsView”属性 HashCode=16802356'。BindingExpression:Path=CustomerTagsView; DataItem=H

我知道这是一种不好的做法,但我已经在代码中创建了一个网格,并希望将该网格绑定到我的视图

到目前为止,我已经:

视图:


但从未输入Get方法。我做错了什么?

我的错。。该方法在我的情况下工作,只是绑定不正确

System.Windows.Data错误:40:BindingExpression路径错误: 在“对象”上未找到“CustomerTagsView”属性 HashCode=16802356'。BindingExpression:Path=CustomerTagsView; DataItem=HashCode=16802356;目标元素是 “ContentPresenter”名称=;目标属性是“内容”类型 “对象”

这是一个重要的教训。在运行到StackOverflow之前,请始终检查输出窗口

<UserControl.Resources>
    <DataTemplate x:Key="container">
        <Border>
            <ContentPresenter Content="{Binding}" />
        </Border>
    </DataTemplate>
</UserControl.Resources>
<ContentControl Content="{Binding newThing.CustomerTagsView}" ContentTemplate="{StaticResource container}"/>
    private Grid _customerTagsView;
    public Grid CustomerTagsView
    {
        get { return _customerTagsView; }
        set 
        { 
            _customerTagsView = value;
            OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("CustomerTagsView"));
        }
    }
<UserControl.Resources>
    <DataTemplate x:Key="container">
        <Border>
            <ContentPresenter Content="{Binding}" />
        </Border>
    </DataTemplate>
</UserControl.Resources>
<ContentControl Content="{Binding newThing.CustomerTagsView}" ContentTemplate="{StaticResource container}"/>