2014-10-02 29 views
1

我知道這是不好的做法,但我在代碼中創建了一個網格,並希望將此網格綁定到我的視圖。是否有可能將Xaml中的內容綁定到代碼中的網格

到目前爲止,我有:

查看:

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

代碼

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

但從未進入Get方法。我做錯了什麼?

回答

0

我的壞..方法,其工作只是在我的情況下,結合被不正確......

System.Windows.Data Error: 40 : BindingExpression path error: 'CustomerTagsView' property not found on 'object' ''' (HashCode=16802356)'. BindingExpression:Path=CustomerTagsView; DataItem='' (HashCode=16802356); target element is 'ContentPresenter' (Name=''); target property is 'Content' (type 'Object')

的一個重要教訓。在運行到StackOverflow之前,請務必檢查您的輸出窗口

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