为UserControl定义一个集合类型的依赖属性,当这个属性用于绑定外部Observable类型的集合类时,Observable集合里的数据发生增加减少为什么用户控件里的依赖属性不发生变化?
定义的依赖属性:
public IEnumerable ItemSource
{
get { return (IEnumerable)GetValue(ItemSourceProperty); }
set { SetValue(ItemSourceProperty, value); }
}
public static readonly DependencyProperty ItemSourceProperty =
DependencyProperty.Register("ItemSource", typeof(IEnumerable), typeof(MyChart), new PropertyMetadata(null, new PropertyChangedCallback(OnSourceChanged)));
static void OnSourceChanged(object sender, DependencyPropertyChangedEventArgs args)
{
MessageBox.Show("dasda");
}
UserControl中子对象与此依赖属性相绑定:
<PathFigure x:Name="Figure" Segments="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=ItemSource,UpdateSourceTrigger=PropertyChanged,Converter={StaticResource cvt}}"/>
外部的Observable类型的集合类与此依赖属性相绑定:
<user:MyChart ItemSource="{Binding Segs,Mode=TwoWay}" x:Name="Chart"/>
现在的问题是,外部数据集合增删后通知不到UserControl中内部对应控件显示更新。
定义的依赖属性:
public IEnumerable ItemSource
{
get { return (IEnumerable)GetValue(ItemSourceProperty); }
set { SetValue(ItemSourceProperty, value); }
}
public static readonly DependencyProperty ItemSourceProperty =
DependencyProperty.Register("ItemSource", typeof(IEnumerable), typeof(MyChart), new PropertyMetadata(null, new PropertyChangedCallback(OnSourceChanged)));
static void OnSourceChanged(object sender, DependencyPropertyChangedEventArgs args)
{
MessageBox.Show("dasda");
}
UserControl中子对象与此依赖属性相绑定:
<PathFigure x:Name="Figure" Segments="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=ItemSource,UpdateSourceTrigger=PropertyChanged,Converter={StaticResource cvt}}"/>
外部的Observable类型的集合类与此依赖属性相绑定:
<user:MyChart ItemSource="{Binding Segs,Mode=TwoWay}" x:Name="Chart"/>
现在的问题是,外部数据集合增删后通知不到UserControl中内部对应控件显示更新。