Xamarin Forms with Prism Demo Project OpenSource for Community #2243
Replies: 2 comments 1 reply
-
Thanks for sharing. There are a number of examples here of what NOT to do in your sample. Some feedback for you: // Your Code
public string Name
{
get
{
return _name;
}
set
{
SetProperty(ref _name, value, "Name");
UpdateButtonStatus();
}
} While this works, you likely want to only invoke UpdateButtonStatus when the value actually changed... this can be more easily done like: public string Name
{
get => _name;
set => SetProperty(ref _name, value, UpdateButtonStatus);
} In your MasterDetailPage you have explicitly set the Detail... I generally advise that you always do this from the navigation uri like <MasterDetailPage.Detail>
<NavigationPage>
<x:Arguments>
<views:Page1Page/>
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Detail> In your TabbedPageExample your Tab Page looks like: <TabbedPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="PrismFullNavigation.Views.TabPageExample"
xmlns:viewmodels="clr-namespace:PrismFullNavigation.ViewModels"
x:DataType="viewmodels:TabPageExampleViewModel"
xmlns:local="clr-namespace:PrismFullNavigation.Views"
xmlns:prism="http://prismlibrary.com"
Title="{Binding TitlePage}">
<local:Tab1Page
prism:ViewModelLocator.AutowireViewModel="False"
BindingContext="{Binding TabPage1}"/>
<local:Tab2Page
prism:ViewModelLocator.AutowireViewModel="False"
BindingContext="{Binding TabPage2}"/>
</TabbedPage> With a ViewModel: public class TabPageExampleViewModel : BaseViewModel
{
public Tab1PageViewModel TabPage1 { get; set; }
public Tab2PageViewModel TabPage2 { get; set; }
public TabPageExampleViewModel(INavigationService navigationService) : base(navigationService)
{
TabPage1 = new Tab1PageViewModel(navigationService);
TabPage2 = new Tab2PageViewModel(navigationService);
}
public override void Initialize(INavigationParameters parameters)
{
base.Initialize(parameters);
TitlePage = "TabbedPage";
}
} This is actually highly problematic for a variety of reasons... most notably you're passing in a bad instance of the Navigation Service to Tab1 and Tab2... you do this actually in a number of places.. this is not something you should ever do. While I personally generally refrain from even having an explicit tabbed page in my apps, and instead dynamically create them with the Prism Uri parameters... in the event that you are explicitly creating the tabs in XAML and thus wouldn't need to register them it's still highly encouraged that if you use the ViewModelLocator to autowire those views. In that case particularly in Prism 7 you would need to manually autowire them. You may additionally want to avoid some reflection lookup cost and you can do that by either registering the Views for Navigation anyway along with their ViewModel like: containerRegistry.RegisterForNavigation<ViewA, ViewAViewModel>(); Or you can simply register them with the ViewModelLocationProvider since the NavigationService won't actually be creating them for you: ViewModelLocationProvider.Register<ViewA, ViewAViewModel>(); Note that this is done for you in the RegisterForNavigation extension. In your BaseViewModel and MenuPageViewModel you're creating a tight coupling to the app with a static property and really it ultimately looks like you're trying to do something funky that if you were using the Navigation Service properly you'd achieve without issue. case 5:
App.Instance.ClearDetailNavStack = false;
navResult = await NavigationService.NavigateAsync("NavigationPage/Page1ClearStackNavPage");
App.Instance.ClearDetailNavStack = true;
break; |
Beta Was this translation helpful? Give feedback.
-
@dansiegel i fix, almost all, issues you mentioned. Thanks you so much! |
Beta Was this translation helpful? Give feedback.
-
Hi,
I have developed a project that contains the most important/used (i have used) Xamarin Forms Prism's features.
I want to share with Community, for Testing, Demo and for anyone purpose.
https://github.com/giuseppenovielli/XF-Prism-Full-Navigation-Example
Enjoy!
Beta Was this translation helpful? Give feedback.
All reactions