mvvm - Cannot seem to communicate between views -


Text after "

I have written an MVVM prototype as a learning exercise and I understand how I interact between views.Let I am struggling to explain to me.

I left (leftSideView)

right (rightSideView)

MainWindow (2 times seen above that mentioned above and A divider is included) There is a treeview on the ListView

What I have applied is not working and if you tell me I am saying wrong or I If Gar is a better way of doing this then I would love to. You can download quick prototype from here

Surely I am doing something wrong with Bindind, besides it, it would be good to learn how you do it. On the left list (one view) on LIVEbox list (another view) on how to communicate between u two.

Thanks any of many suggestions

I took a look at your code, Made the revisions shown below, and it worked. I changed the scene on the right just to make it a little easier to have a TextBlock.

MainWindow.xaml.cs (to create a visual model to force both ideas)

  public partial class main window {public main window ()} {InitializeComponent ( ); } Public static ProtoViewModel MainViewModel = New ProtoViewModel (repository. GetContinents ()); }  

LeftSideView.xaml.cs (set the data reference of this view to be a visible model and update the selected model of the visual model while changing)

 < Code> Public partial squares LeftSideView {Public LeftSideView () {InitializeComponent (); this. Datacontax = main wando Manovy Model; } /// & lt; Summary & gt; /// Update the selected city of view model /// & lt; / Summary & gt; /// & lt; Param name = "sender" & gt; & Lt; / Param & gt; /// & lt; Param name = "e" & gt; & Lt; / Param & gt; {{ProtoViewModel as this.DataContext} as CityViewModel .SelectedCity = e.NewValue Private Zero OnTreeSelectedItemChanged (e Object Sender, RoutedPropertyChangedEventArgs & lt; Object & gt;); }}  

RightSideView.xaml.cs (set the view to the right of using the same visual model)

  Public partial class RightSideView {public RightSideView (public) ) {InitializeComponent (); this. Datacontax = main wando Manovy Model; }}  

In RightSideView.xaml, I just put the text box that is shown below:

  & lt; TextBlock text = "{Binding SelectedCity.Details. City.Name}" />  

When a city is selected on the left, it will replace the selected city on the visual model, therefore, it will update the name of the selected city to the correct view.

Here's what the Prototype model class is:

  Public category ProtoViewModel: Corps. VisualModelBase {public ProtoViewModel (IEnumerable & lt; continentInfo> continents) {Continents = new readonly selection & lt; ContinentViewModel & gt; (Select the new continent viewmodel (continent) from continents to continents. ToList ()); } Public ViewDel. CityValue Model Selected City {Get {return selectedCity; } Set {if (selectedCity! = Value) {selectedCity = value; OnPropertyChanged ("SelectedCity"); }}} Private Vidodels. Cityvalemodel selected whistle; Public readline collection & lt; Continental viewmodel & gt; Continents ({return continents;} set {if (continent! = Value) {continents = value; OnPropertyChanged ("continents")}}}} private readline collection & lt; continentViewModel & gt; continents;}  

I'll share the modified files with you, but I'm not sure how to do this :)


Comments