I'm having an issue have a property shared between two derived ViewModels:
public abstract class MyBaseViewModel : ViewModelBase
{
private string _sharedProperty;
public string SharedProperty
{
get => _sharedProperty;
set => this.RaiseAndSetIfChanged(ref _sharedProperty, value);
}
}
public abstract class ViewModelA : MyBaseViewModel
{
}
public abstract class ViewModelB : MyBaseViewModel
{
}
public sealed partial class FirstPage : IViewFor<ViewModelA>
{
this.Bind(ViewModel,
vm => vm.SharedProperty,
view => view.MycontrolA.Text)
.DisposeWith(disposable);
}
public sealed partial class SecondPage : IViewFor<ViewModelB>
{
this.Bind(ViewModel,
vm => vm.SharedProperty,
view => view.MycontrolB.Text)
.DisposeWith(disposable);
}
When I update SharedProperty from SecondPage, the binding on FirstPage is not updated. Now obviously each ViewModel has its own instance of that property since it's not static. Since RaiseAndSetIfChanged needs an instance to execute, how can we have a property that is bound in two different views and share its binding??