我知道这是不好的做法,但我在代码中创建了一个Grid,并希望将此网格绑定到我的视图中。
我到目前为止:
查看:
<ContentPresenter Content="{Binding CustomerTagsView}"/>
代码
private Grid _customerTagsView;
public Grid CustomerTagsView
{
get { return _customerTagsView; }
set
{
_customerTagsView = value;
OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("CustomerTagsView"));
}
}
但永远不会输入Get
方法。我做错了什么?
答案 0 :(得分:0)
我的不好..这个方法在我的情况下起作用,绑定是不正确的......
System.Windows.Data错误:40:BindingExpression路径错误: &#39; CustomerTagsView&#39;在&#39; object&#39;上找不到的属性&#39;&#39;&#39; (的HashCode = 16802356)&#39 ;. BindingExpression:路径= CustomerTagsView; 的DataItem =&#39;&#39; (的HashCode = 16802356);目标元素是 &#39; ContentPresenter&#39; (名称=&#39;&#39);目标属性是&#39;内容&#39; (类型 &#39;对象&#39)
一个重要的教训。在运行到StackOverflow
之前,请务必检查输出窗口<UserControl.Resources>
<DataTemplate x:Key="container">
<Border>
<ContentPresenter Content="{Binding}" />
</Border>
</DataTemplate>
</UserControl.Resources>
<ContentControl Content="{Binding newThing.CustomerTagsView}" ContentTemplate="{StaticResource container}"/>