I want to pass SecondViewModel SecondProperty value to ViewModel myProperty and show the value on TextBlock. i want the codi
If you need that, you should create a VM DataSource to create a dependency in your first VM.
public class YourViewModelDataSource
{
private ViewModel viewModel;
private SecondViewModel secondViewModel;
public YourViewModelDataSource(ViewModel viewModel, SecondViewModel secondViewModel)
{
this.viewModel = viewModel;
this.secondViewModel = secondViewModel;
}
public void CreateDataSource()
{
this.secondViewModel.PropertyChanged += this.OnSecondViewModelPropertyChanged;
}
private void OnSecondViewModelPropertyChanged(object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
//As pointed in comments, you need to have the second property in your first ViewModel then do this.
case "SecondProperty":
this.viewModel.myProperty = this.secondViewModel.SecondProperty;
break;
}
}
}
When you create your VMs then use this class to create the dependency. Every time SecondViewModel
SecondProperty changes, the ViewModel
myProperty will be raised. I hope it's clear, let me know if you need something else