Can not Navigate to Master Detail Page - xamarin.forms

i have axamarin app with login page that leads to modules launcher landing page
one of those modules is a master details page
every thing is working fine from VS (debug / release) ether emulator or real device
however out of VS, from emulator or device itself if i run the app everything work fine except the navigation to master detail page (without any response)
i tried to navigate to a detailed page directly (without the master page) it works
i tried to put a "/" at the start or remove it , i tried "/NavigationPage" or without it
still not working from the app outside VS.
i did the latest update (7.2.0.1422)
here is my xml codes :
navigation button from landing page
<ImageButton Grid.Row="1"
Grid.Column="2"
HeightRequest="80"
BackgroundColor="WhiteSmoke"
Source="homescreenbtn12.png"
Command="{Binding NavigationCommand}"
CommandParameter="NavigationPage/MwaslaMasterDetailPage"
IsVisible="{Binding CurrentUser.IsTPEmplyess}"/>
2.master details page it self
<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:prism="http://prismlibrary.com"
prism:ViewModelLocator.AutowireViewModel="True"
x:Class="TPS.Modules.Mwasla.Views.MwaslaMasterDetailPage"
xmlns:views="clr-namespace:TPS.Modules.Mwasla.Views;assembly=TPS.Modules.Mwasla">
<MasterDetailPage.Master>
<views:MwaslaMasterPageMenu/>
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<NavigationPage>
<x:Arguments>
<views:MwaslaContactUsPage/>
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Detail>
the normally navigation command
async void ExecuteCommandName(string parameter)
{
await NavigationService.NavigateAsync(parameter);
}
kindly help

There are a few issues I want to address here...
<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:prism="http://prismlibrary.com"
prism:ViewModelLocator.AutowireViewModel="True"
x:Class="TPS.Modules.Mwasla.Views.MwaslaMasterDetailPage"
xmlns:views="clr-namespace:TPS.Modules.Mwasla.Views;assembly=TPS.Modules.Mwasla">
<MasterDetailPage.Master>
<views:MwaslaMasterPageMenu/>
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<NavigationPage>
<x:Arguments>
<views:MwaslaContactUsPage/>
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Detail>
Core Concepts
In this sample there are essentially 3 pages that need to be understood...
The Master Page (MwaslaMasterPageMenu)... it's fine if you want to separate the View for the Master into another XAML page but remember that this should NOT have it's own ViewModel nor should you attempt to set AutowireViewModel on that page.
The MasterDetailPage... this is the actual root navigation context that you are navigating from. This is the page that requires the ViewModel which you have explicitly set AutowireViewModel on
The Detail Page (MwaslaContactUsPage in a NavigationPage)... while this is technically correct for a Xamarin.Forms app and would allow you navigate to /MwaslaMasterDetailPage, it's not recommended that you do this. You should instead be explicit in setting the Detail /MwaslaMasterDetailPage/NavigationPage/MwaslaContactUsPage
Issues with Navigation
Navigation in Prism.Forms is based on the Page which you want to Navigate from in context. This is why in the past there requirements that the Navigation service was a named parameter. Before Prism resolves the ViewModel, it first constructs a new instance of the NavigationService and provides it the navigation context (the Xamarin.Forms.Page aka the View) that the ViewModel will be attached to.
Fixes
First you'll want to move all of the logic from the MwaslaMasterPageMenuViewModel and move it to the MwaslaMasterDetailPageViewModel
Get rid of the MwaslaMasterPageMenuViewModel and remove the AutowireProperty from the MwaslaMasterPageMenu.xaml
Remember that a MasterDetailPage is meant to be the NavigationRoot. This means that if you look at the MasterDetailPage's Parent, it should be your App.
Remember that in order to get the classic "Hamburger" look that people typically want with the MasterDetailPage your Detail needs to be a NavigationPage. In order to achieve this correctly you should refrain from explicitly setting the Detail Page so that you properly navigate to any detail page within the MasterDetailPage, ie /MyMasterDetailPage/NavigationPage/ViewA
When considering the previous comment remove references like /MyMasterDetailPage or /NavigationPage/MyMasterDetailPage
Navigating from the Master aka "Menu"
Remember that when you're navigating from the Master Page aka the Menu, you're navigating not from the Master Page at all but from the MasterDetailPage. As such you will simply do a relative navigation like NavigationPage/ViewA or NavigationPage/ViewB for anything that will change out the Detail Page.

finally it works
thanks Dan Siegel for detailed answer
It Work like Magic

Related

The type 'page' does not support direct content

I create new Uno Cross-Platform App 2.2 from template.
When I open Shared->MainPage.xaml in doesn't open designer in code view there is a underlined error The type 'page' does not support direct content
<Page
x:Class="App6.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App6"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<TextBlock Text="Hello, world!" Margin="20" FontSize="30" />
</Grid>
</Page>
This is an Intellisense issue which happens when the project selector (the DropDown at the top of the XAML editor) is not on the UWP project, but rather on iOS, Android or another platform.
If you select the UWP project, close the editor, and re-open it again, the errors will disappear.
As of Visual Studio 2019 16.5 the issue is still present, but is likely to be addressed in a future version.
At the beginning I can use designer to edit MainPage.xaml in Shared folder, after one moment (there was an error that crashed my VS) not any more...
So solution is to move MainPage.xml to UWP project, edit there, and than move it back.
That's work for now.
Maybe it would work with linked file.
I used Blend for Visual Studio to open and edit the file. The next time I opened the project with VS the problem was fixed.

Why do I get the default header at the top of my NavigationPage, when navigating to root in Xamarin.Forms with Prism?

I have an iOS app written in Xamarin.Forms that uses the Prism NavigationService for navigation. When a user presses the Logout button, navigation returns to the Login Screen. After doing this more than once, the header reappears.
I have been suppressing the NavigationPage header on every screen with the code
NavigationPage.SetHasNavigationBar(this, false);
This works initially. However it stops working after popping off the navigation stack a few times.
On the login page where this occurs, I've also tried adding the following in XAML with the same result.
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:BIMSMobile.ViewModels"
NavigationPage.HasNavigationBar="False"
x:Class="BIMSMobile.Views.LoginPage">
<ContentPage.Content>
...
I suppress the NavigationPage header in favor of a custom view that has the Logout button.
The logout button has the following handler:
protected void OnLogoutClicked(object sender, EventArgs e)
{
SessionHelper.Instance.SignOutUser();
}
In the SessionHelper I do the following:
await NavigationService.NavigateAsync("NavigationPage/LoginPage");
The blue header is suppressed when the app is opened and is maintained for the first few back navigations (pop). I expect this to always be the case. However after the second time of logging out the default header reappears, push the rest of my content down on the screen.
Apparently this was not caused by Navigation or by incorrectly calling SetHasNavigationBar in code. It was caused by styles in the resources :\ My fix is below.
<Style TargetType="NavigationPage">
<Setter Property="HasNavigationBar" Value="False" />
</Style>

Prism Partial views xamarin forms

I am using Prism to build xamarin forms apps.
I have never used Partial Views and cannot find any examples out there.
Can somebody point me to an example,so that I can see if fits what I am trying to achieve?
many thanks
From the Docs:
The concept of a Partial View is to support a custom layout which may
be reused across multiple pages, and eliminate ViewModel logic
duplication by allowing that custom layout to rely on its own
ViewModel. To use a Partial View you must set the
ViewModelLocator.AutowirePartialView property with a reference to the
containing page as shown here. You should not set the
ViewModelLocator.AutowireViewModel property on the Partial View unless
you are explicitly opting out as setting this property to true
directly may result in the ViewModel being incorrectly set.
Example:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:AwesomeApp.Views"
xmlns:prism="clr-namespace:Prism.Ioc;assembly=Prism.Forms"
xmlns:mvvm="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
x:Name="self"
x:Class="AwesomeApp.Views.ViewA">
<StackLayout>
<local:AwesomeView mvvm:ViewModelLocator.AutowirePartialView="{x:Reference self}" />
<Entry Text="{Binding SomeValue" />
</StackLayout>
</ContentPage>

Can I add App.xaml back to a Xamarin.Forms project while using Caliburn.Micro?

The Caliburn.Micro Xamarin.Forms samples (both setup and features illustrate the use of App.cs with no accompanying App.xaml.
I'd like to have an App.xaml file though so I can add in App-level resources into xaml which are now supposed in Xamarin.Forms. Is this possible? How do I do it?
Note, I haven't added one afterwards ever and this is untested, but it should work something like this.
The App.xaml was introduced later into the Xamarin.Forms packages and templates, probably due to the introduction of the app-level resources you are referring to. But basically, the App.xaml isn't different from any other XAML file.
Add a new App.xaml file which looks somewhat like this:
<?xml version="1.0" encoding="utf-8"?>
<Application xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="YourNamespace.YourClass">
<Application.Resources>
<!-- Application resource dictionary -->
</Application.Resources>
</Application>
Note that you need to supply your own namespace in the x:Class="YourNamespace.YourClass" attribute. Now in the same class that you specify here, which should be in your App.cs, make sure the class is marked as partial and the InitializeComponent(); is called in the constructor.
Lastly, make sure that your App.xaml file is marked to be an EmbeddedResource as build action.
In fact that is everything there is to it.
If you want to link your App.xaml and App.xaml.cs file so that they are shown as one node in Visual Studio, open your csproj file in a text-editor and find the <Compile Include="App.xaml.cs" /> node. Edit this to be:
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
While this looks nicer, it's not absolutely necessary.

Resource can't be found even when it's present

I've got a really weird issue I can't fix within a Wpf Application. We built a Common Library containing many useful components, one of them is a fancy MessageBox which has the company style. There're three dictionaries that contains nearly everything we require:
<ResourceDictionary Source="/Library;component/Style/Styles.xaml" />
<ResourceDictionary Source="/Library;component/Themes/Globals.xaml"/>
<ResourceDictionary Source="/Library;component/Themes/Controls/Button/Template.xaml"/>
There's a footer for the MessageBox into Globals.xaml, footer uses a template from Template.xaml. It works perfectly but not in one case. I have a main window that dinamically create a plugin and open a window. This window is a regular Window Wpf application loaded through reflection.
Method to open MessageBox is within the same DLL as Resource Dictionaries.
If I call this MessageBox method from the plugin it throws an exception because "Footer" is not found. I set a breakpoint before
window.ShowDialog();
And I see MergedDictionaries is empty into window. Also empty everywhere, only owner of this MessageBox contains those resources. Doing
window.FindResource("key");
Get a null value as expected. However, if I manually copy merged dictionaries using this code lines before open dialog:
foreach (var dict in owner.Resources.MergedDictionaries)
{
window.Resources.MergedDictionaries.Add(dict);
}
And then look for window.FindResource("key") I can see the style, but even though it continues throwing an exception:
Cannot find resource named '{Footer}'. Resource names are case sensitive.
Footer style is used in this line of MessageBox:
<StatusBar Style="{StaticResource Footer}" DataContext="{Binding ElementName=window}"...
I've also tried to declare this resource into the DialogWindow in the library, even when I've not gonna be allowed to change it:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Library;component/Themes/Generic.xaml" />
<ResourceDictionary Source="/Library;component/Themes/Globals.xaml"/>
<ResourceDictionary Source="/Library;component/Themes/Controls/Button/Template.xaml"/>
</ResourceDictionary.MergedDictionaries>
I've been 2 days knocking my head on the monitor and nothing, everything I tried failed. Despite of breaking a monitor of course.
Ran out of ideas...
Regards.
Make sure of the following things
The resource dictionary Build Action is set to Page
Every project that references the Style has a library reference to it (Even if you put the Dictionary in App.xaml if a project that doesn't reference the Resources Library then it wont find it
Place the MergedDictionaries in App.xaml (or in the specific page you want to use them)

Resources