wpf - Genrating Views (UserControls) using ContentControl -


I have a UserControl (MainView) that needs to display itself in other UserControl based on some condition, This will display AView or BView (they both appear in the same place in the MainView). I am using ViewModel's first approach, so the visual templates are generated by:

  Public category AVView: UserControl {} Public Class LiveView: UserControl {} Public Class AviModel: View MODELBase {} Public Class BVM Model: From the point of use of resource, there is a difference between these two approaches:  

1) With a content control

  & lt; Content control content = "{some binding some models}" /> personal viewloadbase _ somewellmodel; Set up Public ViewModelBase SomeViewModel {get_someViewModel;} {if (! ReferenceEquals (_someViewModel, value)) {_someViewModel = value; RaisePropertyChange (SomeViewModel); }}}   

In this way, I can set the ViewWind (AViewModel or BViewModel) to some ViewModel, and select appropriate view to display data templates.

2) Control the visibility of each of the two content controls, and each of them (only visible at the same time). ContentControl Content = "{Binding AViewModel}" Visibility = "{Binding SomeCondition}" / & gt; & Lt; Content Control Content = "{Binding BViewModel}" Visibility = "{Not Compulsive No Condition}" />

So, from the point of view of resource management, switching between these two ideas will behave in any way, or in both cases will only one scene remain in memory at a fixed time? WPF unloads objects that are not visible at any time, although only one of your two views will be loaded for both, although your second method will create two content controls in the UI, While the first one only creates the same.

Also, see model changes when you set content to a ViewModel Since then, DataTemplate will be evaluated, and WPF should see how to remove the view modal. DataTemplate

In the search I personally prefer the first version. Once there is only one ContentControl in the UI, especially when you have more than just 2 views and it is easy to maintain,

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

java - Reaching JTextField in a DocumentListener -

c# - Add Image in a stackpanel based on textbox input -