S
S
sharpb2018-08-23 08:49:47
WPF
sharpb, 2018-08-23 08:49:47

Navigation in wpf application - how to implement?

Hello. Literally a week I started using wpf and c#, before that I was a nodejs developer.
When I started writing my own wpf application, I got the idea to change pages in the main window.
How I implemented it within the framework of mvvm:
For example, we have 5 pages, therefore, in the main xaml, I registered my own DataTemplate for each with an indication of the view (User controls), i.e. how to register them. Registered 5 times.
Further, in the main viewmodel, I organized CurrentView, where I store the current viewmodel (user control) and, accordingly, when the button is pressed, a command is launched that changes the CurrentView.
Everything works, but there are many disadvantages:
- The need to register for each view and viewmodel its own DataTemplate in Window.Resources. Those. if I have 20 views, then it will be just tin.
- For each button that performs navigation, you need to create your own command that will change the view. All of these commands will have code duplication with a difference of one word.
- No possibility to dynamically add pages.
What is the easiest way to implement normal managed navigation. By the way, I'm writing on my mvvm bike. For a small project, I see no reason to use prism or catel. MvvmLight, In general, the campaign is running and there is no documentation. The links on the site give 403.
Yes, and so for educational purposes it is interesting to see, so please do not advise frameworks.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WayMax, 2018-08-23
@WayMax

For the page "container" use "Frame" (with the NavigationUIVisibility="Hidden" parameter).
For the pages themselves, write classes inherited from the "Page" class.
To display the page: an instance of ClassFrame.Navigate(an instance ofPageClass).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question