Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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.</p> <p>MainWindow.xaml.cs (Create a view model for both views to bind to)</p> <pre><code>public partial class MainWindow { public MainWindow() { InitializeComponent(); } public static ProtoViewModel MainViewModel = new ProtoViewModel(Repository.GetContinents()); } </code></pre> <p>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)</p> <pre><code>public partial class LeftSideView { public LeftSideView() { InitializeComponent(); this.DataContext = MainWindow.MainViewModel; } /// &lt;summary&gt; /// Update the selected city of the view model /// &lt;/summary&gt; /// &lt;param name="sender"&gt;&lt;/param&gt; /// &lt;param name="e"&gt;&lt;/param&gt; private void OnTreeSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs&lt;object&gt; e) { (this.DataContext as ProtoViewModel).SelectedCity = e.NewValue as CityViewModel; } } </code></pre> <p>RightSideView.xaml.cs (set the right side view to use the same view model)</p> <pre><code>public partial class RightSideView { public RightSideView() { InitializeComponent(); this.DataContext = MainWindow.MainViewModel; } } </code></pre> <p>In the RightSideView.xaml, I just put the textbox that is shown below:</p> <pre><code>&lt;TextBlock Text="{Binding SelectedCity.Details.City.Name}"/&gt; </code></pre> <p>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.</p> <p>Here's what the ProtoViewModel class looked like:</p> <pre><code>public class ProtoViewModel : Core.ViewModelBase { public ProtoViewModel(IEnumerable&lt;ContinentInfo&gt; continents) { Continents = new ReadOnlyCollection&lt;ContinentViewModel&gt;( (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&lt;ContinentViewModel&gt; Continents { get { return continents; } set { if (continents != value) { continents = value; OnPropertyChanged("Continents"); } } } private ReadOnlyCollection&lt;ContinentViewModel&gt; continents; } </code></pre> <p>I would share the modified files with you, but I'm not sure how to do that :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload