我创建了课程:
class StorageBase
{
public Queue<Slices> Slices {get;set;}
}
和wpf自定义控件,它具有StorageBase类型的依赖属性存储:
public StorageBase Storage
{
get { return (StorageBase)GetValue(StorageProperty); }
set { SetValue(StorageProperty, value); }
}
public static readonly DependencyProperty StorageProperty =
DependencyProperty.Register("Storage", typeof(StorageBase), typeof(MaterialStreamControl), new UIPropertyMetadata(null, new PropertyChangedCallback(OnStoragePropertyChanged)));
static void OnStoragePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
(d as MaterialStreamControl).Render();
}
如果存储中的切片发生了变化,我怎么能重新渲染组件?
答案 0 :(得分:1)
通常,StorageBase会实现INotifyPropertyChanged。然后,Slices上的setter将引发INotifyPropertyChanged.PropertyChanged事件。
编辑:你可能还想让Slices成为ObservableCollection而不是Queue。 http://msdn.microsoft.com/en-us/library/ms668604.aspx