WPF binding: how to change a property when changing the property of its property

I created a class:

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

and a wpf user control with the Storage dependency property of type 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();
        }

How can I retrain a component if the slices in the repository are changed?

+3
source share
1 answer

Typically, StorageBase will implement INotifyPropertyChanged. Then the slicer installer raises the INotifyPropertyChanged.PropertyChanged event.

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

EDIT: you can also make Slices ObservableCollection instead of queue. http://msdn.microsoft.com/en-us/library/ms668604.aspx

+1

Source: https://habr.com/ru/post/1752774/


All Articles