I have an usercontrol, which have a property Results . This usercontrol should show this ObservableCollection . I think the XAML-Code of the usercontrol doesn't matter. The Code-Behind look like that:
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))
In my MainView.xaml I have the following XAML-Code to show the usercontrol:
<controls:ResourcesGridData Results="{Binding Path=ResultsToShow}" />
I want to bind the ResultsToShow property of the MainViewModel to the property of the usercontrol.
But now I get the following error:
System.Windows.Data.BindingExpression ist kein Wert des Typs ASSESS.Data.ResultModel und kann in dieser generischen Auflistung nicht verwendet werden.
I try to translate it:
System.Windows.Data.BindingExpression is not a value of the type ASSESS.Data.ResultModel and can not be used in this generic list.
Okay, it's very simple. In my case, I don't need any properties in the usercontrol code-behind.
In the MainView I simply write this:
<controls:ResourcesGridData />
and in the usercontrol:
ItemsSource="{Binding ResultsToShow}"
I directly bind to the Property of the DataContext of the MainView.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.