繁体   English   中英

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

[英]Is it possible to bind Content in Xaml To a Grid in code

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

到目前为止,我有:

视图:

            <ContentPresenter Content="{Binding CustomerTagsView}"/>

    private Grid _customerTagsView;
    public Grid CustomerTagsView
    {
        get { return _customerTagsView; }
        set 
        { 
            _customerTagsView = value;
            OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("CustomerTagsView"));
        }
    }

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

我的糟糕。方法只是在我的情况下绑定不正确...

System.Windows.Data错误:40:BindingExpression路径错误:在'object''''(HashCode = 16802356)'上找不到'CustomerTagsView'属性。 BindingExpression:路径= CustomerTagsView; DataItem =''(HashCode = 16802356); 目标元素是'ContentPresenter'(Name =''); 目标属性为“内容”(类型为“对象”)

重要的一课。 在运行StackOverflow之前,请务必检查您的输出窗口

<UserControl.Resources>
    <DataTemplate x:Key="container">
        <Border>
            <ContentPresenter Content="{Binding}" />
        </Border>
    </DataTemplate>
</UserControl.Resources>
<ContentControl Content="{Binding newThing.CustomerTagsView}" ContentTemplate="{StaticResource container}"/>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM