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.
Related
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.
Is there a good/efficent way to have a MasterDetailPage (FlyoutPage) while also having shell like tabs at the bottom of the page?
Because I am using Prism I assume that using Shell as well is probably not ideal.
The Gmail and MyAnimeList App are great references for what I am trying to archive.
Prism and shell don't work properly together. You should create a MasterDetail Page, and in it, as part of the detail page, you should add a NavigationPage.
From here, you can try two things inside the NavigationPage
a Tabbed page inside the navigation page (I haven't tried this approach though)
You could use a normal ContentPage and inside that, add TabView from XamarinCommunity Toolkit
https://learn.microsoft.com/en-us/xamarin/community-toolkit/views/tabview
I want to create a carousel page in my Xamarin Forms App using Fresh MVVM, the problem is that FreshMVVM does not offer a class to create a carousel page like it does with FreshNavigationContainer or with FreshMasterDetailNavigationContainer, so I cant bind the page with the view model nor I can call it from my navigation stacks.
I have found two or three posts about this matter, but all of them were outdated (from 2016 or 2017) and they did not have a way to implement carousel pages using Fresh MVVM.
With this said, is there any way to implement a carousel page in 2020 or it is still impossible?
As CarouselView is control available in Xamarin.Forms 4.4, you can use it like any other Xamarin control including in Fresh MVVM.
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 have been looking at Prism to host an old Winforms application. This is being used in our migration from Winforms -> WPF in our company. However, I have come across some issues.
In short I have a project outlined like so:
Project Outline
DataManager WPF Project
MEF Module that on Initialize registers a view with the region manager and references the old winforms project
- View -- which contains a WPF UserControl and has a WindowsFormsHost which points to the main view of the old winforms project.
DataManager Winforms project
Contains an old Module that needs to be intialized with views
Host
Contains the shell and bootstrapper
- Shell has the main region in which the WPF DataManager View gets injected into.
So the problem I am having is as follows. The old Winforms view loads correctly in the WPF shell via the new WPF view. However, any content added to the view after this does not get updated. I tried adding some buttons to the screen. I also tried clearing all the controls.
Looking around here, I went with the suggestion of listening to the Size Changed event and calling Child.Refresh on the WPFHost, but still this did not work.
Is this a WPF specific issue like discussed here : Does WPF refresh drawing similar to Windows Forms?
Or is it an issue with not refreshing the view in the region manager correctly? WPF, Prism v2, Region in a modal dialog, add region in code behind
Neither of which seem to work!
Perhaps I need to fire a redraw or similar in the winforms control itself?
Edit: Calling a Refresh() after updating the UI did not resolve the issue.
Edit 2: Also tried this in the old Winforms (.net 2.0) application and it displayed correctly!
Ok, I added a standard winforms project with some controls instead of the legacy project I am using and it worked. It is possibly missing some steps in the initialization of the legacy winforms project.