gpt4 book ai didi

binding - WPF 绑定(bind) : how to make property being changed when the property of it's property changed

转载 作者:行者123 更新时间:2023-12-02 04:15:15 27 4
gpt4 key购买 nike

我创建了类:

class StorageBase
{
public Queue<Slices> Slices {get;set;}
}

和 wpf 自定义控件,它具有 StorageBase 类型的依赖属性 Storage:
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();
}

如果存储中的切片发生更改,我如何重新渲染组件?

最佳答案

通常 StorageBase 会实现 INotifyPropertyChanged。然后 Slices 上的 setter 将引发 INotifyPropertyChanged.PropertyChanged 事件。

示例:http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.propertychanged.aspx

编辑:您可能还想让 Slices 成为 ObservableCollection 而不是队列。
http://msdn.microsoft.com/en-us/library/ms668604.aspx

关于binding - WPF 绑定(bind) : how to make property being changed when the property of it's property changed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3163878/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com