I took a look at your code, made the modifications shown below, and it worked. I changed the right side view to just have a textblock to simplify it a bit.
MainWindow.xaml.cs (Create a view model for both views to bind to)
public partial class MainWindow
{
public MainWindow()
{
InitializeComponent();
}
public static ProtoViewModel MainViewModel = new ProtoViewModel(Repository.GetContinents());
}
LeftSideView.xaml.cs (set the data context of this view to be the view model and update the selected city of the view model when changed)
public partial class LeftSideView
{
public LeftSideView()
{
InitializeComponent();
this.DataContext = MainWindow.MainViewModel;
}
/// <summary>
/// Update the selected city of the view model
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnTreeSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
(this.DataContext as ProtoViewModel).SelectedCity = e.NewValue as CityViewModel;
}
}
RightSideView.xaml.cs (set the right side view to use the same view model)
public partial class RightSideView
{
public RightSideView()
{
InitializeComponent();
this.DataContext = MainWindow.MainViewModel;
}
}
In the RightSideView.xaml, I just put the textbox that is shown below:
<TextBlock Text="{Binding SelectedCity.Details.City.Name}"/>
When a city on the left view is selected, it will changed the selected city on the view model, therefore, it will updated the selected city name on the right view.
Here's what the ProtoViewModel class looked like:
public class ProtoViewModel : Core.ViewModelBase
{
public ProtoViewModel(IEnumerable<ContinentInfo> continents)
{
Continents =
new ReadOnlyCollection<ContinentViewModel>(
(from continent in continents
select new ContinentViewModel(continent)).ToList());
}
public ViewModels.CityViewModel SelectedCity
{
get { return selectedCity; }
set
{
if(selectedCity != value)
{
selectedCity = value;
OnPropertyChanged("SelectedCity");
}
}
}
private ViewModels.CityViewModel selectedCity;
public ReadOnlyCollection<ContinentViewModel> Continents
{
get { return continents; }
set
{
if (continents != value)
{
continents = value;
OnPropertyChanged("Continents");
}
}
}
private ReadOnlyCollection<ContinentViewModel> continents;
}
I would share the modified files with you, but I'm not sure how to do that :)