我有一個usercontrol,它有一個屬性結果。這個用戶控件應該顯示這個ObservableCollection。我認爲用戶控件的XAML代碼並不重要。代碼隱藏看起來像:WPF綁定到用戶控件的屬性
Public Property Results() As ObservableCollection(Of ResultModel)
Get
Return GetValue(ResultsProperty)
End Get
Set(ByVal value As ObservableCollection(Of ResultModel))
SetValue(ResultsProperty, value)
End Set
End Property
Public Shared ReadOnly ResultsProperty As DependencyProperty = _
DependencyProperty.Register("Results", _
GetType(ObservableCollection(Of ResultModel)), GetType(ResourcesGridData), _
New FrameworkPropertyMetadata(Nothing))
在我MainView.xaml我有以下XAML代碼傳送到顯示用戶控件:
<controls:ResourcesGridData Results="{Binding Path=ResultsToShow}" />
我想將ResultsToShow屬性綁定將MainViewModel的屬性設置爲usercontrol的屬性。
但現在我得到以下錯誤:
System.Windows.Data.BindingExpression ist kein Wert des Typs ASSESS.Data.ResultModel und kann in dieser generischen Auflistung nicht verwendet werden.
我試着翻譯一下:
System.Windows.Data.BindingExpression is not a value of the type ASSESS.Data.ResultModel and can not be used in this generic list.
MainViewModel是此UserControl(ResourcesGridData)的DataContext,還是實際與主窗口/父級控件關聯? – Damascus 2011-06-01 10:34:08
該評論幫助我很多。我不知道,MainView的DataContext自動是usercontrol的DataContext – rakete 2011-06-01 10:43:30
那麼你是否解決了你的問題? :) – Damascus 2011-06-01 10:44:37