Note that there are some explanatory texts on larger screens.

plurals
  1. POHandling Navigation in MVVM WPF application
    primarykey
    data
    text
    <p>I am developing a WPF application that follows MVVM. Now I am handling navigation of views in the following manner. MainWindow View</p> <pre><code>&lt;Border&gt; &lt;StackPanel&gt; &lt;local:Home Content="{Binding CurrentView,Converter={StaticResource ViewConverterHome}, UpdateSourceTrigger=PropertyChanged}"/&gt; &lt;local:Page1 Content="{Binding CurrentView,Converter={StaticResource ViewConverterPage1}, UpdateSourceTrigger=PropertyChanged}"/&gt; &lt;local:Page2 Content="{Binding CurrentView,Converter={StaticResource ViewConverterPage2}, UpdateSourceTrigger=PropertyChanged}"/&gt; &lt;/StackPanel&gt; &lt;/Border&gt; </code></pre> <p>Home, Page1,Page2 are 3 views. HomeVM,Page1VM,Page2VM are view models corresponding to the views. There is a class call ApplicationViewModel that contains a property CurrentView of type CViewModelBase which is the parent class for all three viewmodels. ApplicationViewModel handles the navigation in the folowing manner</p> <pre><code> private void OnUserInputNextClicked(object sender, OperationInformationChangedEventArgs e) { do { if (this.CurrentView is HomeVM) { this.CurrentView = null; Page1VM page1 = new Page1VM("BNM", "MATH HONS", "13"); page1.NextCilcked += new EventHandler&lt;OperationInformationChangedEventArgs&gt;(OnUserInputNextClicked); page1.BackCilcked += new EventHandler&lt;OperationInformationChangedEventArgs&gt;(OnUserInputBackClicked); this.CurrentView = page1; break; } if (this.CurrentView is Page1VM) { this.CurrentView = null; Page2VM page2 = new Page2VM("Kolkata", "Monoj", "Itachuna"); page2.NextCilcked += new EventHandler&lt;OperationInformationChangedEventArgs&gt;(OnUserInputNextClicked); page2.BackCilcked += new EventHandler&lt;OperationInformationChangedEventArgs&gt;(OnUserInputBackClicked); this.CurrentView = page2; break; } if (this.CurrentView is Page2VM) { this.CurrentView = null; HomeVM home = new HomeVM("Anirban", "30"); home.NextCilcked += new EventHandler&lt;OperationInformationChangedEventArgs&gt;(OnUserInputNextClicked); this.CurrentView = home; break; } } while (false); } </code></pre> <p>The navigation is working perfectly; But dispose of disappeared views are not getting called.So all the views live till the end. Is there any way to prevent 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.
 

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