NET MAUI how to create a hamburger menu - maui

I am trying to create a hamburger menu in xaml, but zero success. I was trying to use the samples provided [here][1], but zero success.
My idea is to create a view model that has a list of FlyoutItems then inject this view model to the AppShell.
public partial class ShellViewModel : ObservableObject
{
public List<FlyoutItem> FlyoutItems { get; private set; } = new List<FlyoutItem>();
public ShellViewModel()
{
AddMenuItems();
}
private void AddMenuItems()
{
var flyoutItems = new List<FlyoutItem>
{
new FlyoutItem
{
Title = "Item 1"
},
new FlyoutItem
{
Title = "Item 2"
}
};
FlyoutItems.AddRange(flyoutItems);
}
}
public partial class AppShell : Shell
{
private ShellViewModel viewModel => BindingContext as ShellViewModel;
public AppShell(ShellViewModel viewModel)
{
BindingContext = viewModel;
RegisterRoutes();
InitializeComponent();
}
private void RegisterRoutes()
{
Routing.RegisterRoute(PageRoutes.LoginPage, typeof(LoginPage));
Routing.RegisterRoute(PageRoutes.RegisterPage, typeof(RegisterPage));
Routing.RegisterRoute(PageRoutes.HomePage, typeof(MainPage));
Routing.RegisterRoute(PageRoutes.DetailsPage, typeof(PlayerDetailsPage));
Routing.RegisterRoute(PageRoutes.AddOrUpdatePage, typeof(AddOrUpdatePlayer));
}
}
In the XAML sometign like this
<?xml version="1.0" encoding="UTF-8" ?>
<Shell
x:Class="MauiUI.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiUI"
xmlns:pages="clr-namespace:MauiUI.Pages">
<Shell.ItemTemplate>
<DataTemplate>
<CollectionView BindingContext="{x:Reference shell}"
IsGrouped="True"
ItemsSource="{Binding FlyoutItems}">
<CollectionView.ItemTemplate>
<DataTemplate>
<Label Text="{Binding Title}"
TextColor="White"
FontSize="18" />
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</DataTemplate>
</Shell.ItemTemplate>
<ShellContent
Title="Amazons of Volleyball"
ContentTemplate="{DataTemplate pages:SplashPage}"
Route="HomePage" />
</Shell>
thnx
[1]: https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/shell/flyout?view=net-maui-7.0

I am trying to create a hamburger menu in xaml, but zero success.
You can add this code in your AppShell.xaml:
<?xml version="1.0" encoding="UTF-8" ?>
<Shell
x:Class="MauiUI.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiUI"
xmlns:views="clr-namespace:MauiUI.Pages">
<FlyoutItem FlyoutDisplayOptions="AsMultipleItems">
<ShellContent Title="Home"
Route="home"
ContentTemplate="{DataTemplate local:MainPage}" />
<ShellContent Title="NewPage1"
ContentTemplate="{DataTemplate pages:NewPage1}" />
</FlyoutItem>
</Shell>
Or you can add this code in your AppShell.xaml.cs:
public partial class AppShell : Shell    
{
  public AppShell ()        
{
        InitializeComponent ();
        
        FlyoutItem flyoutItem = new FlyoutItem ();
        flyoutItem.FlyoutDisplayOptions = FlyoutDisplayOptions.AsMultipleItems;
        
        flyoutItem.Items.Add (new ShellContent () { Title = "NewPage1", Content = new NewPage1 () });
        flyoutItem.Items.Add (new ShellContent () { Title = "home", Content = new MainPage () });
        
        myshell.Items.Add (flyoutItem);
        
}
    
}

Related

OnPlatform Conditional in .NET MAUI FlyoutItem Items Colleciton

In .NET MAUI, how do I use the OnPlatform element to conditionally include a ShellContent item in a FlyoutItem Items collection?
This Xaml will not compile (namespaces removed for clarity)
<Shell>
<FlyoutItem>
<OnPlatform x:TypeArguments="Items">
<On Platform="iOS">
<ShellContent
Title="Map"
ContentTemplate="{DataTemplate pages:MapPage}"
Route="MapPage" />
</On>
<On Platform="Android">
<ShellContent
Title="Map"
ContentTemplate="{DataTemplate pages:AMapPage}"
Route="MapPage" />
</On>
</OnPlatform>
There is a property IsVisible for ShellContent , you can use bind to achieve this.
Please refer to the following code:
AppShell.xaml.cs
public partial class AppShell : Shell
{
public bool isVisible_Android { get; set; }
public bool isVisible_iOS { get; set; }
public AppShell()
{
InitializeComponent();
if (Microsoft.Maui.Devices.DeviceInfo.Platform == DevicePlatform.iOS )
{
isVisible_iOS = true;
}
else if (DeviceInfo.Platform == DevicePlatform.Android)
{
isVisible_Android = true;
}
BindingContext = this;
}
}
AppShell.xaml
<FlyoutItem Title="Home" >
<ShellContent Title="Map" Route="MapPage" ContentTemplate="{DataTemplate local:MapPage}" IsVisible="{Binding isVisible_iOS}" />
<ShellContent Title="Map" Route="AMapPage" ContentTemplate="{DataTemplate local:AMapPage}" IsVisible="{Binding isVisible_Android}"/>
</FlyoutItem>

Trying to display a popup gives "The Parent must be of type Microsoft.Maui.Handlers.PageHandler."

Trying to follow this example to display a custom popup but using MVVM and Shell gives me the error in the title:
https://www.youtube.com/watch?v=yM7opXlu-MU&ab_channel=GeraldVersluis
namespace MyPopupTest
{
public partial class MyViewModel : ObservableObject
{
public MyViewModel()
{
DisplayMyPopup();
}
private void DisplayMyPopup()
{
var popup = new MyPopup();
Shell.Current.ShowPopup(popup);
}
}
}
the popup
using CommunityToolkit.Maui.Views;
namespace MyPopupTest;
public partial class MyPopup : Popup
{
public MyPopup()
{
InitializeComponent();
}
}
This results in an exception: The Parent must be of type Microsoft.Maui.Handlers.PageHandler.
and the stack trace:
at CommunityToolkit.Maui.Core.Views.MauiPopup.SetElement(IPopup element) in /_/src/CommunityToolkit.Maui.Core/Views/Popup/MauiPopup.macios.cs:line 71
at CommunityToolkit.Maui.Core.Handlers.PopupHandler.ConnectHandler(MauiPopup platformView) in /_/src/CommunityToolkit.Maui.Core/Handlers/Popup/PopupHandler.macios.cs:line 91
at Microsoft.Maui.Handlers.ElementHandler`2[[CommunityToolkit.Maui.Core.IPopup, CommunityToolkit.Maui.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[CommunityToolkit.Maui.Core.Views.MauiPopup, CommunityToolkit.Maui.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].OnConnectHandler(Object platformView)
at Microsoft.Maui.Handlers.ElementHandler.ConnectHandler(Object platformView)
at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view)
at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler)
at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value)
at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context)
at CommunityToolkit.Maui.Views.PopupExtensions.CreatePopup(Page page, Popup popup) in /_/src/CommunityToolkit.Maui/Views/Popup/PopupExtensions.shared.cs:line 59
at CommunityToolkit.Maui.Views.PopupExtensions.ShowPopup[LayingTrackPopup](Page page, LayingTrackPopup popup) in /_/src/CommunityToolkit.Maui/Views/Popup/PopupExtensions.shared.cs:line 27
at MyPopupTest.MyViewModel.DisplayLayingPopup() in /Users/…
Are you sure You are following all steps? Like setting all paths in xaml, setting good references. I have recreated this task but was not able to get this error.
Working example:
Downloading from nuget CommunityToolkit.Maui (version 2.0.0), CommunityToolkit.Mvvm (version 8.0.0)
MauiProgram.cs
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
})
.UseMauiCommunityToolkit();
return builder.Build();
}
}
MainPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:viewmodels="clr-namespace:MauiPopup"
x:DataType="viewmodels:MainPageViewModel"
x:Class="MauiPopup.MainPage">
<ScrollView>
<VerticalStackLayout
Spacing="25"
Padding="30,0"
VerticalOptions="Center">
<Image
Source="dotnet_bot.png"
SemanticProperties.Description="Cute dot net bot waving hi to you!"
HeightRequest="200"
HorizontalOptions="Center" />
<Label
Text="Hello, World!"
SemanticProperties.HeadingLevel="Level1"
FontSize="32"
HorizontalOptions="Center" />
<Label
Text="Welcome to .NET Multi-platform App UI"
SemanticProperties.HeadingLevel="Level2"
SemanticProperties.Description="Welcome to dot net Multi platform App U I"
FontSize="18"
HorizontalOptions="Center" />
<Button
x:Name="CounterBtn"
Text="Click me"
SemanticProperties.Hint="Counts the number of times you click"
Command="{Binding ShowPopupCommand}"
HorizontalOptions="Center" />
</VerticalStackLayout>
</ScrollView>
</ContentPage>
MainPage.xaml.cs
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
BindingContext = new MainPageViewModel();
}
}
MainPageViewModel.cs
internal class MainPageViewModel : ObservableObject
{
public ICommand ShowPopupCommand { get; }
public MainPageViewModel()
{
//ShowPopupCommand = new Command(ShowPopup);
ShowPopup();
}
private void ShowPopup()
{
var popup = new PopupPage();
Shell.Current.ShowPopup(popup);
}
}
PopupPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<mct:Popup xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:mct="clr-namespace:CommunityToolkit.Maui.Views;assembly=CommunityToolkit.Maui"
x:Class="MauiPopup.PopupPage">
<StackLayout>
<Label Text="Welcome to Maui Popup!"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
</StackLayout>
</mct:Popup>
PopupPage.xaml
public partial class PopupPage : Popup
{
public PopupPage()
{
InitializeComponent();
}
}

How to bind attributes values in MAUI component

I'm trying to make a windows-like navigation item.
This is the implementation:
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="NavItem.NavItem"
xmlns:local="clr-namespace:NavItem"
x:DataType="local:NavItem">
<Frame HeightRequest="50" CornerRadius="6" BackgroundColor="{StaticResource Tertiary}" BorderColor="{StaticResource Secondary}" Padding="10">
<Frame.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped" />
</Frame.GestureRecognizers>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label x:Name="LblText" Text="{Binding Text}" Grid.Column="0" TextColor="{StaticResource White}" />
<Label Text=">" Grid.Column="1" TextColor="{StaticResource White}" FontSize="16" />
</Grid>
</Frame>
</ContentView>
public partial class NavItem : ContentView
{
string text;
public string Text
{
get => text;
set { text = value; OnPropertyChanged(); }
}
public string PageName { get; set; }
public NavItem()
{
InitializeComponent();
}
private async void TapGestureRecognizer_Tapped(object sender, EventArgs e)
{
await Shell.Current.GoToAsync(PageName);
}
}
<VerticalStackLayout>
<local:NavItem Text="Page 1" PageName="Page1" />
<local:NavItem Text="Page 2" PageName="Page2" />
</VerticalStackLayout>
The navigation is ok but the binding fails to set Text property of label LblText.
So this is the rendering:
EDIT: I also tried with a bindable attribute, same result
public string Text
{
get => (string)GetValue(TextProperty);
set { SetValue(TextProperty, value); OnPropertyChanged(); }
}
public static readonly BindableProperty TextProperty =
BindableProperty.Create(nameof(Text), typeof(string), typeof(NavItem), "", BindingMode.TwoWay);
I just had to set the binding context to itself:
public NavItem()
{
InitializeComponent();
BindingContext = this;
}

Xamarin Forms - Set BindingContext of a controltemplate

I have a xamarin forms application. It has a tabbedpage within it multiple tabs. The tabbedpage and te tabs, each of them has their own viewmodel as a bindingcontext.
In the app.xaml I defined a controltemplate. I use this control template in each tab, because I want each of those tabs to have a button at the bottom of the page.
At this moment: the button in the controltemplate binds with a property defined in each tab. But I want the button to bind at one place. Isn't it possible to create a viewmodel special for the controltemplate and bind the button defined in the controltemplate with that viewmodel?
Current code:
<ControlTemplate x:Key="ActivityStatusButton">
<StackLayout>
<ContentPresenter>
</ContentPresenter>
<StackLayout VerticalOptions="EndAndExpand" HorizontalOptions="Fill" Padding="15">
<Button Style="{StaticResource RedBackGroundWithWhiteTextButtonStyle}" Command="{TemplateBinding BindingContext.ClickOnStatusButton, Mode=TwoWay}" Text="{TemplateBinding BindingContext.ok, Mode=TwoWay}"></Button>
</StackLayout>
</StackLayout>
</ControlTemplate>
A typical tab:
<ContentPage ...>
<ContentPage.Content>
<Label Text="hello"></Label>
</ContentPage.Content>
<!--The control template is placed here (the button) -->
You could create a Custom Control (a subclass of ContentView) like
<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Name="template"
x:Class="App24.MyControlTemplate">
<ContentView.Content>
<StackLayout VerticalOptions="EndAndExpand" HorizontalOptions="Fill" Padding="15">
<Button Clicked="Button_Clicked" Command="{Binding Source={x:Reference template},Path=ButtonCommand}" Text="{Binding Source={x:Reference template},Path=ButtonText}" CommandParameter="{Binding Source={x:Reference template},Path=CommandParameter}" />
</StackLayout>
</ContentView.Content>
</ContentView>
using System;
using System.Windows.Input;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace App24
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MyControlTemplate : ContentView
{
public event EventHandler ButtonClick;
public static readonly BindableProperty ButtonTextProperty =
BindableProperty.Create("ButtonText", typeof(string), typeof(MyControlTemplate), default(string));
public string ButtonText
{
get => ((string)GetValue(ButtonTextProperty));
set => SetValue(ButtonTextProperty, value);
}
public static readonly BindableProperty ButtonCommandProperty =
BindableProperty.Create("ButtonCommand", typeof(ICommand), typeof(MyControlTemplate), null, BindingMode.Default, null);
public ICommand ButtonCommand
{
get => (ICommand)GetValue(ButtonCommandProperty);
set
{
SetValue(ButtonCommandProperty, value);
}
}
public static readonly BindableProperty CommandParameterProperty =
BindableProperty.Create("CommandParameter", typeof(object), typeof(MyControlTemplate), null);
public object CommandParameter
{
get => (object)GetValue(CommandParameterProperty);
set => SetValue(CommandParameterProperty, value);
}
public MyControlTemplate()
{
InitializeComponent();
}
private void Button_Clicked(object sender, EventArgs e)
{
ButtonClick?.Invoke(sender, e);
}
}
}
Now you could add it to any page and binding Text , Command or CommandParameter in code behind .
<StackLayout VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand">
<local:MyControlTemplate ButtonText="{Binding ButtonText}" ButtonCommand="{Binding ClickCommand}" CommandParameter="test" />
</StackLayout>

Getting error from login to master details page in xamarin.forms in view model?

When i trying to navigate from login page to masterDetailpage, I am getting error says
"System.Reflection.TargetInvocationException
Message=Exception has been thrown by the target of an invocation."
I tried this in the login function when user successful logged in
async void Login()
{
try
{
var current = Connectivity.NetworkAccess;
if (current == NetworkAccess.Internet)
{
if (IsValidated)
{
await navigationRef.PushPopupAsync(new LoaderPage()).ConfigureAwait(false);
userDetails = await webServicesRepository.UserLogin(Phone, Password, "123113123", "Android").ConfigureAwait(false);
if (userDetails != null && userDetails.status == "200")
{
await navigationRef.PopPopupAsync().ConfigureAwait(false);
MasterDetailPage fpm = new MasterDetailPage
{
Master = new MainMenuPageMaster(),
Detail = new NavigationPage(new HomePage())
};
Application.Current.MainPage = fpm;
//Application.Current.MainPage = new NavigationPage(new MainMenuPage());
//await navigationRef.PushAsync(new MainMenuPage()).ConfigureAwait(false);
}
else
{
await navigationRef.PopPopupAsync().ConfigureAwait(false);
await Application.Current.MainPage.DisplayAlert(Constants.DISPLAY_POPUP_TITLE, Constants.NO_DATA_FOUND, Constants.DISPLAY_POPUP_BUTTON).ConfigureAwait(false);
}
}
else
{
await Application.Current.MainPage.DisplayAlert(Constants.DISPLAY_POPUP_TITLE, "You must fill all areas correctly!", Constants.DISPLAY_POPUP_BUTTON).ConfigureAwait(false);
}
}
else
{
await Application.Current.MainPage.DisplayAlert(Constants.DISPLAY_NETWORK_ERROR_TITLE, Constants.DISPLAY_NETWORK_ERROR_MESSAGE, Constants.DISPLAY_POPUP_BUTTON).ConfigureAwait(false);
}
}
catch(Exception ex)
{
Console.WriteLine(ex.InnerException.Message);
await Application.Current.MainPage.DisplayAlert(Constants.DISPLAY_POPUP_TITLE, Constants.NO_DATA_FOUND, Constants.DISPLAY_POPUP_BUTTON).ConfigureAwait(false);
}
}
MasterDetailPage :
<?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:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="intSetSet.MainMenuPage"
xmlns:views="clr-namespace:XXXXXX"
NavigationPage.HasNavigationBar="False"
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
ios:Page.UseSafeArea="true">
<MasterDetailPage.Master>
<views:MainMenuPageMaster x:Name="masterPage" Title="Menu" Icon="ListIcon.png" />
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<NavigationPage>
<x:Arguments>
<views:HomePage />
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Detail>
</MasterDetailPage>
c#
public partial class MainMenuPage : MasterDetailPage
{
public MainMenuPage()
{
InitializeComponent();
try
{
masterPage.MenuItemsListView.ItemSelected += ListView_ItemSelected;
MessagingCenter.Subscribe<EventArgs>(this, "OpenMenu", args =>
{
IsPresented = !IsPresented;
});
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
var item = e.SelectedItem as MainMenuPageModel;
if (item == null)
return;
var page = (Page)Activator.CreateInstance(item.TargetType);
//var page = item.TargetType;
page.Title = item.Title;
Detail = new NavigationPage(page);
IsPresented = false;
masterPage.MenuItemsListView.SelectedItem = null;
}
}
ContentPage to generate List options:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="XXXXX.MainMenuPageMaster"
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
ios:Page.UseSafeArea="true">
<StackLayout>
<ListView x:Name="MenuItemsListView"
SeparatorVisibility="None"
x:FieldModifier="public"
HasUnevenRows="true"
ItemsSource="{Binding MenuItems}">
<ListView.Header>
<StackLayout BackgroundColor="#CEDAEE">
<StackLayout Orientation="Horizontal"
Padding="20">
<Image Margin="10,10,0,0"
Source="setsetlogo.png"
WidthRequest="80"
HeightRequest="80"
HorizontalOptions="Start"></Image>
<Label HorizontalOptions="StartAndExpand"
VerticalTextAlignment="Center"
Text="IntSetSet"
TextColor="White"
FontSize="24" />
</StackLayout>
<BoxView BackgroundColor="Teal"
HorizontalOptions="FillAndExpand"
HeightRequest="1"></BoxView>
</StackLayout>
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout HorizontalOptions="FillAndExpand"
BackgroundColor="#CEDAEE">
<StackLayout Padding="10,10"
Orientation="Horizontal">
<Image Source="{Binding Icon}"
WidthRequest="40"
HeightRequest="40"
VerticalOptions="Center"
HorizontalOptions="Start"></Image>
<Label VerticalOptions="Center"
VerticalTextAlignment="Center"
HorizontalTextAlignment="Start"
HorizontalOptions="StartAndExpand"
TextColor="White"
Text="{Binding Title}"
FontSize="Medium" />
</StackLayout>
<BoxView BackgroundColor="Teal"
HorizontalOptions="FillAndExpand"
HeightRequest="1"></BoxView>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.Footer>
<StackLayout BackgroundColor="#CEDAEE" Orientation="Horizontal" HorizontalOptions="FillAndExpand">
<Button Command="{Binding LogoutCommand}" Text="LogOut" BackgroundColor="#CEDAEE" TextColor="Yellow" HorizontalOptions="EndAndExpand">
</Button>
<!--<Button Clicked="LogoutButton_Clicked" Text="LogOut" BackgroundColor="#CEDAEE" TextColor="Yellow" HorizontalOptions="EndAndExpand">
</Button>-->
</StackLayout>
</ListView.Footer>
</ListView>
</StackLayout>
</ContentPage>
C#
public partial class MainMenuPageMaster : ContentPage
{
public MainMenuPageMaster()
{
InitializeComponent();
BindingContext = new MainMenuPageViewModel();
}
}
View Model:
public class MainMenuPageViewModel : INotifyPropertyChanged
{
public ObservableCollection<MainMenuPageModel> MenuItems { get; set; }
public ICommand LogoutCommand { get; }
public MainMenuPageViewModel()
{
try
{
MenuItems = new ObservableCollection<MainMenuPageModel>(new[]
{
new MainMenuPageModel { Id = 0, Title = "Home", Icon="shop.png", TargetType= typeof(HomePage) },
new MainMenuPageModel { Id = 1, Title = "Profile", Icon="shop.png", TargetType= typeof(ProfilePage) },
new MainMenuPageModel { Id = 2, Title = "Referral History", Icon="paper_money.png", TargetType= typeof(ReferralHistoryPage) },
});
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
#region INotifyPropertyChanged Implementation
public event PropertyChangedEventHandler PropertyChanged;
void OnPropertyChanged([CallerMemberName] string propertyName = "")
{
if (PropertyChanged == null)
return;
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
I want to Navigate from the login page to master details page on successful login