This is basically the lightweight question. I recently started migrating myself from WPF to UWP and faced some issues with differences between those two platforms. And one of them is navigation, so to say. I would like to ask you, guys about major navigation approaches in UWP applications with MVVM in-behind.
In WPF I had a general Storage of all the ViewModels, and the ContentControl took the CurrentViewModel value from that storage and then showed the corresponding View. Here, I guess, I can do it as well, but I would like to approach it with UWP Navigating Services. How do I do that?
I can do it as well, but I would like to approach it with UWP Navigating Services. How do I do that?
Sure, you could Use NavigationService to implement this feature, and u could get current root frame with Window.Current.Content as Frame; and bind the NavigationViewItem with Page type, when the item selected, you could get current page type and call NavigationService to navigate page that you want.
For getting the complete code sample, please install Template Studio for UWP, and make UWP project with this.
Related
I have application based on Shell. Application contains pages with tabs which are deffined in Shell. Everything works properly and correctly.
I need create second level page with tabs whitch contains options for return to previous page. In the case of standard "ContentPage", "Routing.RegisterRoute" and "Shell.Current.GoToAsync" it is no problem. However, if I create a TabbedPage like this, my application ends with exception:
0xFFFFFFFFFFFFFFFF in Android.Runtime.JNIEnv.monodroid_debugger_unhandled_exception
I am aware of this information:
TabbedPage is incompatible with .NET MAUI Shell apps, and an exception will be thrown if you attempt to use TabbedPage in a Shell app.
However, I am not sure if this also applies to the second level page, or only to pages that are directly referenced in Shell.
How can I create second level page with tabs?
Is there anyone who has encountered a similar problem, or someone who can give me advice?
Thanks a lot
Using shell, you are limited to content pages.
Navigating to such page is not a problem. Calling GoToAsync will give you the "second layer" you request.
The more interesting part is how to implement tab control, so you have tabs in that ContentPage.
One way to solve this is by using BindableLayouts.
(Here is a good example: https://dev.to/davidortinau/making-a-tabbar-or-segmentedcontrol-in-net-maui-54ha)
You can make really neat UI with this.
It will be worth your time.
Ask if you have any questions.
You can combine TabbedPage, FlyoutPage and NavigationPage instead of shell if you really want to create second level page with tabs. Obviously shell is based on flyouts and tabs, so if you use FlyoutPage and TabbedPage alone in your project, it will be more flexible and troublesome than the shell.
These are the documents about the specific use of FlyoutPage and TabbedPage, you can refer to them if you need: https://learn.microsoft.com/en-us/dotnet/maui/user-interface/pages/flyoutpage?view=net-maui-7.0 and https://learn.microsoft.com/en-us/dotnet/maui/user-interface/pages/navigationpage?view=net-maui-7.0.
Hope this will help you.
I have started building an app on Xamarin Studio using Prism with Xamarin.Forms. My issue is that I can't seem to find a snippet of code as an example of MasterDetail navigation inside the app.
Every time I navigate to a page it just renders a new view on top of the previous master view. Is there an example somewhere, or instructions on how to use switchable views in order to achieve master/detail navigation with prism on xamarin? I have found some prism examples for windows forms applications but nothing specific to xamarin forms.
Thank you in advance and sorry for the generalized question.
Check out the sandbox sample that is in the Prism repo.. It's actually quite simple.
https://github.com/PrismLibrary/Prism/tree/master/Sandbox/Xamarin/HelloWorld
You just have to call navigate from your MasterDetilPage ViewModel. This will set the Detail page accordingly.
As part of a school project, a group and I will develop a Windows application using C#.
We are not very experienced in C# but has some basic understanding for it. We do however have experience from other languages and platforms.
We would like to build an application in which the layout is split into two primary parts: the menu, which will reside to the left and the content which will be to the right.
The menu will be more or less static and when an entry in the menu is chosen, the content will be changed.
We have not been able to figure out the best way for achieving this nor have we been able to find good material on this. The idea is to have one window and add a view (as far as I can understand, this should be a UserControl?) to this window. This control will be the menu.
Now, our question is if anyone can point us in the right direction to achieve the navigation in the program. Say, when a menu entry is clicked, how will we change the content of the window and how will we manage which view is active? I suppose that every view (in the "content area") will have a controller.
We are interested in the "best practices" for this when using WinForms and the MVC pattern.
We hope that someone can help us further in this project.
If I were you I would seriously consider using WPF instead of winforms.
It, and the use of the MVVM pattern, allows you to do some pretty impressive stuff with far less code than if you are using winforms. If you don't already know winforms then it might also be a slightly less steep learning curve as WPF is a better thought out framework (at least in my opinion).
If you go the WPF route spend some time getting to understand how bindings work and how to bind your ViewModel to the UI. Once you have a good understanding of proper UI separation you are able to do far more than you could with the old WinForms framework.
I found this link quite useful when I first started looking at WPF. Especially the RelayCommand.
If you are using Winforms the options that you have got is:
-dynamically clearing forms and generating content on menu navigation
-using mdi container form, which can be parent to a number of child forms
If you are using for WPF you could use Pages in a Frame control loaded based on used menu selection. You could also use MVVM pattern to build your app.
I've done several WPF application(not using MVVM) in the past and I had always to implement my own system of navigation between view(instantiate the view once, and then load in a container component, with refreshing required components of my view).
It works, but:
It's always custom, so if a new developer comes he has to learn of it how it works
I'm pretty sure that It's not the most optimized(most of things haven't been done in background worker, ...)
It's a time loss
So I was wondering if there is an official way to handle this ? I don't exactly how, but I was thinking to a navigation component, which can act a little like a tab panel, or a little like the MVC framework in asp.net, we can call a specified controller for an action and some parameters.
Maybe deactiviting bindings when they aren't in the current view
You can use DataTemplates/Styles to customize content of your control ( not only apearance, but data, cause that what you're asking for I presume)
http://msdn.microsoft.com/en-us/library/ms742521.aspx
You can have one Host control and at runtime change its appearance based on events/ states.
Like an example can have a look here:
http://code.google.com/p/svnradar/ how this program manages a appearance of Group and Flat view of repository information.
Another example:
Podder of Josh Smith
http://joshsmithonwpf.wordpress.com/2008/03/05/podder-v2-has-been-released/
Hope this helps.
You may be interested by Lakana, a lightweight (but powerful) framework that can handle for you all the navigation concerns !
Riana
I have this winForm applications and we are about to rewrite some of the forms with WPF. So my plan so far is to create wpf user controls and add them into classic winforms. So far so good.
Now looking at using an MVVM frame work to make life easier and I cam across Caliburn and ReactiveUI. Caliburn in this scenario is not so easy to use as it needs to be initialised at an application level in a wpf application. Does the same apply to ReactiveUI or can I make it work with a couple of wpf controls?
ReactiveUI doesn't need to be initialized at the app level by default, it should work fine with your scenario. If it doesn't, make sure to ping the mailing list and let me know about it!
For anyone else coming to this question in the future, Caliburn.Micro now has support for initialisation from anywhere (from version 1.1). See this discussion thread.