Let say I have classes like those:
public class ParentModel : INotifyPropertyChanged
{
// INotifyPropertyChanged pattern implemented ...
public IChildViewModel CurrentControlModel {
get { ... } set { /* Notify on changes */ }
}
}
public class ChildModelA : INotifyPropertyChanged, IChildViewModel
{
// INotifyPropertyChanged pattern implemented ...
public ICommand Command {
get { ... } set { /* Notify on changes */ }
}
}
public class ChildModelB : INotifyPropertyChanged, IChildViewModel
{
// INotifyPropertyChanged pattern implemented ...
public ICommand Command {
get { ... } set { /* Notify on changes */ }
}
}
public class ButtonViewModel : INotifyPropertyChanged
{
ICommand Command get { ... } set { /* Notify on changes */ }
}
I would like to have Command
property to reflect the value of parentModelInstance.CurrentControlModel.Command
event if
CurrentControlModel
changes.
I cannot modify the ButtonViewModel.Command
property to be a proxy of the property
because it's the view model for all buttons and I don't want to specialize it for every possible button.
If I do
ButtonViewModel viewModel;
viewModel.Command = parentModelInstance.CurrentControlModel.Command;
it doesn't work because CurrentControlModel
can change (it's null
at startup for instance).
I can listen to PropertyChanged
event but it will cumbersome to do that for all properties of the model.
Any easier and cleaner alternative ?
Context
To give a bit of context, it's part of a dynamic toolbar code where you have buttons that can change icon, be disabled or change command, command target etc...
depending on what is the current focused control (which can be of different type).
CurrentControlModel
is the view model of the current focused control.