Тёмный
No video :(

Prism for Xamarin.Forms - Passing Navigation Parameters 

Brian Lagunas
Подписаться 18 тыс.
Просмотров 13 тыс.
50% 1

When navigating throughout your Prism for Xamarin.Forms applications, it is often required to pass parameters from one View to another. Prism allows you to pass navigation parameters with three simple steps:
1. Create the navigation parameters
2. Get the navigation parameters
3. Read the navigation parameter values
Passing parameters to the next View/ViewModel can be done using an overload of the INavigationService.NavigateAsync method. This overload accepts a NavigationParameters object that can be used to supply data to the next View. The NavigationParameters object can accept any arbitrary object as a value.
Getting the navigation parameters from the target View/ViewModel is done by implementing the INavigationAware interface. The OnNavigatedFrom, OnNavigatingTo, and OnNavigatedTo methods each represent the different phases of the navigation process and expose the INavigationParameters object to you.
You read the INavigationParameters values by using either the index of the collection, the GetValue/GetValues method, or by using the TryGetValue method.
Twitter: / brianlagunas
Blog: brianlagunas.com
GitHub: github.com/bri...
Prism Library: prismlibrary.gi...
Become a Patron: / prismlibrary
Visit our Sponsor: bit.ly/prism-i...

Опубликовано:

 

26 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 46   
@kasozivincent8685
@kasozivincent8685 3 года назад
Thanks a lot Brian. This has saved my evening.
@BrianLagunas
@BrianLagunas 3 года назад
Thanks for watching
@Styx1x
@Styx1x 5 лет назад
another great video. Easy to understand and excellent examples
@BrianLagunas
@BrianLagunas 5 лет назад
Thanks for watching
@user-im7jx6wo3t
@user-im7jx6wo3t 5 лет назад
Great Job! Well Done! Vozmi s polki pirojok!
@BrianLagunas
@BrianLagunas 5 лет назад
Thank you very much
@g00dvibes47
@g00dvibes47 5 лет назад
Brian, thank you for these videos, they are a Godsend; I inherited a project at my current company that uses Xamarin with Prism and it is super unfamiliar yet made straightforward with these videos. Having some issues wrapping my head around some things in this unfamiliar environment, but maybe I can send you a ping for video ideas? Would be a huge help! Thanks again
@BrianLagunas
@BrianLagunas 5 лет назад
Right now, the plan is to cover all the basic topics then move into topic requests. Patron topic requests will have priority, so I recommend becoming a patron so your suggestions is one of the first to be covered. www.patreon.com/prismlibrary
@amanuppal2209
@amanuppal2209 3 года назад
Thank you very much for this vedio!
@BrianLagunas
@BrianLagunas 3 года назад
Thank you very much for watching
@muhammadwaqasaziz4054
@muhammadwaqasaziz4054 4 года назад
Awesome, Awesome, Awesome, Awesome, Awesome JOB MAN!
@BrianLagunas
@BrianLagunas 4 года назад
Thanks you so much
@lopezcr0202
@lopezcr0202 4 года назад
thanks for the video :)
@BrianLagunas
@BrianLagunas 4 года назад
Thanks for watching
@namanvohra8262
@namanvohra8262 3 года назад
A really nice video. However, I am confused as to why the OnNavigatedTo in another ViewModel is not triggered. I have already added the breakpoint as well. The rest of the code is working fine (for instance, data binding).
@BrianLagunas
@BrianLagunas 3 года назад
Hard to say. Usually this indicates an error in code somewhere. Possibly you still have a throw NotImplementedException in another method somewhere
@namanvohra8262
@namanvohra8262 3 года назад
@@BrianLagunas Thanks for the reply. Yes, I solved it yesterday. Indeed it was due to the throw new NotImplementedException. I didnt delete that earlier.
@coderblog
@coderblog 4 года назад
Thanks, I like it!
@BrianLagunas
@BrianLagunas 4 года назад
Thanks for watching
@coderblog
@coderblog 4 года назад
@@BrianLagunas I will watch all of your Prism videos! Because I find that the Prism is great so I am starting to learn it, thanks! XDD
@BrianLagunas
@BrianLagunas 4 года назад
@@coderblog great! Let me know if you have any questions
@coderblog
@coderblog 4 года назад
@@BrianLagunas I will, thanks a lot :)
@fadelmahmoud9964
@fadelmahmoud9964 3 года назад
Thanks for the video. Can someone help me with this issue: OnNavigatedTo( ) is executed once the page is added to stack, so when I navigate pages forward then PopBack to the original page, all binding data are not shown in the page bcs the ViewModel does not execute OnNavigatedTo() function as the page already in the stack. So how to keep the data shown in the page OR how to pass parameters directly to ViewModel constructor ?
@BrianLagunas
@BrianLagunas 3 года назад
When going back in the nav stack the pages do not loose their binding context. OnNavigatedTo gets called both on a forward nav and a back nav. You must have code in your OnNavigatedTo method that is changing state but not considering a back nav operation.
@priyaan2560
@priyaan2560 5 лет назад
Can we able to add collection in Navigated to implemented interface
@BrianLagunas
@BrianLagunas 5 лет назад
Yes. It's no different than any other app you would write.
@zsoltnagy2227
@zsoltnagy2227 4 года назад
Hi. Are you doing in the same way if you want to pass back data(object) from the Second page to the first page?
@BrianLagunas
@BrianLagunas 4 года назад
Yes, call gobackasync and pass your parameters
@rezamohamed2112
@rezamohamed2112 5 лет назад
@Brian Lagunas when I simulate on the iOS simulator, i'm unable to get the Title 'Hello from Main Page' to render immediately on navigation to View A - works just fine on Android however.
@BrianLagunas
@BrianLagunas 5 лет назад
Hard to say. If you feel you found a bug, please report it on the Prism github repo with a sample app to reproduce the issue.
@rezamohamed2112
@rezamohamed2112 5 лет назад
@@BrianLagunas i'm just recreating the one line demo on these videos verbatim. I can't imagine its a bug - just trying to understand if it should work or not on iOS, and possibly trying to figure out why its giving issues on my end.
@Nk54fr
@Nk54fr 4 года назад
Hello Brian, thanks for the video. Do you know why if I create myself a NavigationParameters with the key "__NavigationMode" to set the navigationMode to New myself because I handle the navigation from MasterDetailPage. I need the __NavigationMode to make the call to OnNavigationFrom and OnNavigatedTo from the MasterDetailPage otherwise, I can't have the Initialize/OnNavigatedTo/OnNavigatedFrom methods working. I need this because I have some pages you can use from the MasterDetailPage or from the HomePage (the default page on the MasterDetailPage. It's just a gridView with some tiles of my favorite pages. They trigger a navService.NavigateTo whereas the Master section set a new DetailPage with a NavigationPage and the desired page. I hope I made myself clear. Anyway, thanks again for this awesome framework !
@Nk54fr
@Nk54fr 4 года назад
Ok I found it : just cast the NavigationParameters as INavigationParametersInternal, then on the cast, perform the add and it will work :) Exemple given : ((INavigationParametersInternal)navigationParameters).Add("__NavigationMode", NavigationMode.New);
@BrianLagunas
@BrianLagunas 4 года назад
Glad you got it figured out.
@crashnnburn
@crashnnburn 5 лет назад
Hello, I have a quick question. How do I access the ViewModel from the code behind. I need to do stuff in the code behind (refresh a listview) while updating viewmodel variables. Anyone know?
@BrianLagunas
@BrianLagunas 5 лет назад
If you absolutely must access the VM from code behind just cast the BindingContext. Var vm = (MyViewModel)BindingContext
@crashnnburn
@crashnnburn 5 лет назад
@@BrianLagunas Thanks for the fast response. This did the trick! The only other thing I had to do in order for it to work is to use it in the OnAppearing method. If you try to use it in the constructor it won't work because the view is created before the ViewModel. Thanks again!
@andrewbeeman9083
@andrewbeeman9083 4 года назад
Two Questions, 1) are there any Tabbed navigation examples? 2) I was attempting to set up the Resourced Dictionaries like I had before swapping to Prism and I get "A value of type 'Setter' cannot be added to a collection or dictionary of type 'IList` App.xamarin Prism Xamarin." Since you don't do any styling in any of the applications and there's no styling in any of the sample projects, should I assume styling isn't possible? I know that sounds strange but I ask seriously as I have see no examples of it with Prism and I'm getting these errors. One of the guys I work with does Prism on the WPF apps but he didn't know and hadn't seen in before.
@BrianLagunas
@BrianLagunas 4 года назад
Yes, we have plenty of samples. Just check out the sample repo: github.com/PrismLibrary/Prism-Samples-Forms Yes, you can style your Prism apps just like any other XF app. Prism does not do anything different or limit you in any way.
@andrewbeeman9083
@andrewbeeman9083 4 года назад
@@BrianLagunas Do any of the samples have any styling? I couldn't find any. They were all also in 4.7, when I tried them in 4.8 I got errors. I know Gradient brushes are experimental to Xamarin but I've had them for years in other projects and don't really want to give them up.
@BrianLagunas
@BrianLagunas 4 года назад
Prism has no impact on styling. It literally has nothing to do with styling.
@andrewbeeman9083
@andrewbeeman9083 4 года назад
@@BrianLagunas In your first video we replace the application.xaml markup with the prism:PrismApplication markup. After that nothing worked in Xam Forms 4.8. In Forms 4.7 it would run but would break if I had Styles with Setters in the Application.Resources.
@BrianLagunas
@BrianLagunas 4 года назад
@@andrewbeeman9083 I've never had an issue with this. Like I said, Prism does not impact styling in anyway. If anything breaks it's going to be a Xamarin issue, or perhaps you are doing something incorrect.
Далее
Prism for Xamarin.Forms - Navigation Basics
15:09
Просмотров 22 тыс.
Episode 5: MVVM & Data Binding with Xamarin.Forms
30:39
Prism - Using Composite Commands
10:36
Просмотров 14 тыс.
Task vs ValueTask: When Should I use ValueTask?
10:43
FreshMvvm Basic Navigation Concepts in Xamarin.Forms
21:15
Prism - Using Delegate Commands
11:31
Просмотров 36 тыс.
Prism - Using the Event Aggregator
9:14
Просмотров 31 тыс.
I've been using Redis wrong this whole time...
20:53
Просмотров 354 тыс.
microsoft doubles down on recording your screen
10:00
When RESTful architecture isn't enough...
21:02
Просмотров 272 тыс.