Silverlight 自定义控件中的Binding ItemsSource依赖项属性
我有一个自定义控件,它有一个依赖属性,该属性应该填充控件中datagrid的ItemsSource属性。由于某些原因,集合从未被填满,ItemsSource总是以空结束Silverlight 自定义控件中的Binding ItemsSource依赖项属性,silverlight,xaml,binding,custom-controls,Silverlight,Xaml,Binding,Custom Controls,我有一个自定义控件,它有一个依赖属性,该属性应该填充控件中datagrid的ItemsSource属性。由于某些原因,集合从未被填满,ItemsSource总是以空结束 Public Shared ReadOnly ItemsSourceProperty As DependencyProperty = DependencyProperty.Register("ItemsSource", GetType(ObservableObjectCollection), GetType(HomePageCo
Public Shared ReadOnly ItemsSourceProperty As DependencyProperty = DependencyProperty.Register("ItemsSource", GetType(ObservableObjectCollection), GetType(HomePageControl), New PropertyMetadata(New ObservableObjectCollection, New PropertyChangedCallback(AddressOf ItemsSourceCallback)))
Public Property ItemsSource As ObservableObjectCollection
Get
Return DirectCast(GetValue(HomePageControl.ItemsSourceProperty), ObservableObjectCollection)
End Get
Set(value As ObservableObjectCollection)
SetValue(HomePageControl.ItemsSourceProperty, value)
End Set
End Property
Xaml:
我还有五个其他的DPs工作得很好,三个字符串和一种样式(用于设置datagrid的列)以及一个URI。我可以直接设置它们,如“This is optional”(这是可选的),也可以像HeaderText一样绑定它们,但ItemsSource属性似乎从未绑定过。。。控件外部使用与控件内部ItemsSource绑定中使用的绑定相同的绑定的gridview将被填充。。。因此,绑定确实返回一个已填充的集合,但它不会将其发送到自定义控件内的datagrid
如果我将observeObjectCollection更改为我在绑定的集合中使用的对象类型,那么它可以正常工作。我想使用ObserveObjectCollection的原因是因为我想能够将任何对象绑定到datagrid,就像datagrid可以。。。它不关心您绑定到它的类型-如何让我的用户控件不关心?是否触发
PropertyChanged
事件?@anatolig Nothing在设置为observeObjectCollection时触发,ItemsSourceCallback在设置为类型化的observeable集合时触发。
<Controls:HomePageControl x:Name="myControl"
Margin="0,25,0,0"
Grid.Row="1"
HeaderText="{Binding Source={StaticResource MainViewModel}, Path=CurrentUser, Mode=TwoWay, UpdateSourceTrigger=Default}"
HeaderCount="30"
HeaderLinkText="This is optional."
HeaderLinkURI="/Projects"
ItemsSource="{Binding Source={StaticResource MainViewModel}, Path=TaskList, Mode=TwoWay, UpdateSourceTrigger=Default}"
GridViewStyle="{StaticResource RadGridViewStyleNoFlag}"
/>