Code Monkey home page Code Monkey logo

simpletoolkit's Introduction

SimpleToolkit

SimpleToolkit is a .NET MAUI library of helpers and simple, easily customizable controls.

The library consists of these NuGet packages:

I have split the content of this library into multiple NuGet packages because there may be people who want to use only the SimpleShell control, for example, and do not want to use other controls.

Caution

Long-term support is not guaranteed. However, this repository is released under the MIT license, so you can always fork the repository and build the packages yourself.

Here are some of my samples that were built using this library:

       

Marvelous .NET MAUI

       

Gadget Store App  |  Bet App

       

Navbar Animation #1  |  Navbar Animation #2

       

Hamburger Menu App  |  Waste App

Tip

Check out a list of all samples here.

Supported platforms

This library is built for the following platforms:

  • Android
  • iOS/Mac Catalyst
  • Windows (WinUI)

SimpleToolkit.Core

SimpleToolkit.Core Documentation

The SimpleToolkit.Core package is a set of simple .NET MAUI controls and helpers.

These are all the controls this package has to offer:

  • Icon - control that allows you to display a tinted image
  • ContentButton - button that can hold whatever content you want
  • Popover - control that allows you to display custom popovers (flyouts) anchored to any control

In order to use the controls listed above, you need to call the UseSimpleToolkit() extension method in your MauiProgram.cs file:

builder.UseSimpleToolkit();

This package also contains some useful helpers. For example, there are helpers that allow you to force application content to be displayed behind the system bars (status and navigation bars) on Android and iOS.

See documentation for more information.

SimpleToolkit.SimpleShell

SimpleToolkit.SimpleShell Documentation

The SimpleToolkit.SimpleShell package provides you with a simplified implementation of .NET MAUI Shell that lets you easily create a custom navigation experience in your .NET MAUI applications. The implementation is simply called SimpleShell.

All SimpleShell is is just a set of containers for your application content with the ability to put the hosting area for pages wherever you want. This gives you the flexibility to add custom tab bars, navigation bars, flyouts, etc. to your Shell application.

Bear in mind that SimpleShell does not come with any navigation controls. SimpleShell just gives you the ability to use custom navigation controls along with the URI-based navigation and automatic navigation stack management.

Important

Before you begin using SimpleShell, I highly recommend familiarizing yourself with the original .NET MAUI Shell - especially with the URI-based navigation, which works exactly the same as in SimpleShell. The SimpleShell class inherits from the Shell class.

In order to use SimpleShell, you need to call the UseSimpleShell() extension method in your MauiProgram.cs file:

builder.UseSimpleShell();

Why not use SimpleShell and use .NET MAUI Shell instead

  • .NET MAUI Shell offers a platform-specific appearance.
  • Platform-specific navigation controls that .NET MAUI Shell provides probably have better performance than controls composed of multiple .NET MAUI views.
  • A SimpleShell-based application may not have as good accessibility in some scenarios due to the lack of platform-specific navigation controls. .NET MAUI Shell should be accessible out of the box since it uses platform-specific controls.
  • Maybe I have implemented something wrong that has a negative impact on the performance, stability, accessibility, or something like that.

See documentation for more information.

simpletoolkit's People

Contributors

radekvym avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

simpletoolkit's Issues

ButtonContent does not display icon

Downloaded latest version of SimpleToolkit.Core (3.0.0) from Nuget.

Added the UseSimpleToolkit to builder as suggested in documentation

var builder = MauiApp.CreateBuilder(); builder .UseMauiApp<App>() .RegisterAppServices() .UseSimpleToolkit() .RegisterViewModels() .RegisterViews() .ConfigureFonts(fonts => { fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); });
Added the namespace to my page:

xmlns:simpleCore="clr-namespace:SimpleToolkit.Core;assembly=SimpleToolkit.Core"

I didn't see any mention in the documentation as to what the namespace should be so making an assumption that this is the correct one since I was able to access the ButtonContent from it.

And this is the xaml code for the ContentButton:

<simpleCore:ContentButton> <HorizontalStackLayout Padding="12,10" Spacing="10"> <simpleCore:Icon Source="email32.png" TintColor="Red" VerticalOptions="Center" HeightRequest="18" WidthRequest="18"/> <Label Text="Sign in with email" TextColor="White" FontAttributes="Bold" VerticalOptions="Center"/> </HorizontalStackLayout> </simpleCore:ContentButton>
It displays the text ok but not the icon. When I changed the simpleCore:icon TintColor property to red that I spotted a little red square but no image.

I'm testing this with an Android project where my icons (.png) are stored under Platforms\Android\Resources\drawable folder. Note that my icon gets displayed when I use:

<Image Source="email32.png" WidthRequest="30" HeightRequest="30" Margin="10"/>

which would indicate that the icon is available to the project.

Any ideas how to resolve this?

Thanks

[UPDATE] .net 8 support

Dear RadekVyM,

First of all, super thank you for this library and it's super awesome.

Please kindly support .net 8 in near future.
Currently, I'm facing below error at .net 8 project.

image

Best Regards,

Converting from SimpleShell to Shell?

HI,

When trying to convert GadgetStoreApp to use Shell instead of SimpleShell I am receiving the error "The property 'ShellContents' was not found in type 'AppShell'" at AppShell.xaml with this line of code:
BindableLayout.ItemsSource="{Binding Source={x:Reference thisShell}, Path=ShellContents}"
Is it possible to user Shell instead of SimpleShell please?
Thanks,
AG

Back Button Not Center

I have implementation back button, and i have wrong button position.

<simpleShell:SimpleShell.RootPageContainer>
    <Grid
        RowDefinitions="*, 50"
        x:Name="rootContainer">
        <simpleShell:SimpleNavigationHost x:Name="pageContainer"/>
        <controls:TabBarView
            Grid.Row="1"
            ShellItems="{Binding Path=ShellContents, Source={x:Reference thisShell}}"
            VerticalOptions="End" HorizontalOptions="Fill"
            CurrentPageSelectionChanged="TabBarViewCurrentPageChanged"/>
    </Grid>
</simpleShell:SimpleShell.RootPageContainer>

<simpleShell:SimpleShell.Content>
    <Grid
        RowDefinitions="50, *"
        ColumnDefinitions="Auto,*">
        <Button
            x:Name="backButton"
            Text="Back"
            Margin="20,5"
            HorizontalOptions="Start"
            VerticalOptions="Center"
            Background="Black"
            Grid.Column="0"/>
        <Label
            HorizontalOptions="Center"
            VerticalOptions="Center"
            Text="{Binding CurrentShellContent.Title, Source={x:Reference thisShell}}"
            FontAttributes="Bold"
            FontSize="18"
            Grid.Column="1"/>
        <simpleShell:SimpleNavigationHost Grid.Row="1" Grid.ColumnSpan="2"/>
    </Grid>
</simpleShell:SimpleShell.Content>

Whats wrong with my xaml code?

Screenshot 2024-07-11 at 17 23 19

Can not use Simple Shell "Unable to cast object of type 'Microsoft.Maui.Controls.Handlers.ShellItemHandler' to type 'SimpleToolkit.SimpleShell.Handlers.SimpleShellItemHandler"

Hi I wanted to try the toolkit but unfortunately I am getting an error whenever I launch my app on Windows:

{"Unable to cast object of type 'Microsoft.Maui.Controls.Handlers.ShellItemHandler' to type 'SimpleToolkit.SimpleShell.Handlers.SimpleShellItemHandler'."}

What I did was to simply follow the Sample and I tried to track down my issue for the last couple hours without success.

I stripped my shell to the most basic possible and it looks like this:

<?xml version="1.0" encoding="UTF-8" ?>
<simpleShell:SimpleShell
    x:Class="BoxingTimer.AppShell"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:BoxingTimer"
    xmlns:simpleShell="clr-namespace:SimpleToolkit.SimpleShell;assembly=SimpleToolkit.SimpleShell"
    x:Name="thisShell">


    <ShellContent
        Title="Home"
        ContentTemplate="{DataTemplate local:HomePage}"
        Route="MainPage" />

</simpleShell:SimpleShell>

I did include .UseSimpleShell() .UseSimpleToolkit()

Maybe you can help me troubleshooting this, I have tried with a new .NET8 application and it worked fine though

Full stack trace:

at SimpleToolkit.SimpleShell.Handlers.SimpleShellHandler.CreateShellItemHandler()
at SimpleToolkit.SimpleShell.Handlers.SimpleShellHandler.SwitchShellItem(ShellItem newItem, Boolean animate)
at SimpleToolkit.SimpleShell.Handlers.SimpleShellHandler.MapCurrentItem(SimpleShellHandler handler, ISimpleShell shell)
at Microsoft.Maui.PropertyMapper2.<>c__DisplayClass5_0.<Add>b__0(IElementHandler h, IElement v) at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView) at Microsoft.Maui.PropertyMapper.UpdateProperty(IElementHandler viewHandler, IElement virtualView, String property) at Microsoft.Maui.Handlers.ElementHandler.UpdateValue(String property) at SimpleToolkit.SimpleShell.Handlers.SimpleShellHandler.MapContent(SimpleShellHandler handler, ISimpleShell shell) at Microsoft.Maui.PropertyMapper2.<>c__DisplayClass5_0.b__0(IElementHandler h, IElement v)
at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView)
at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView)
at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view)
at Microsoft.Maui.Handlers.ViewHandler2.SetVirtualView(IView view) at Microsoft.Maui.Handlers.ViewHandler2.SetVirtualView(IElement view)
at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler)
at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value)
at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value)
at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context)
at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context)
at Microsoft.Maui.Handlers.WindowHandler.MapContent(IWindowHandler handler, IWindow window)
at Microsoft.Maui.PropertyMapper`2.<>c__DisplayClass5_0.b__0(IElementHandler h, IElement v)
at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView)
at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView)
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.SetHandler(IWinRTObject nativeElement, IElement element, IMauiContext context)
at Microsoft.Maui.Platform.ElementExtensions.SetWindowHandler(Window platformWindow, IWindow window, IMauiContext context)
at Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(Application platformApplication, IApplication application, OpenWindowRequest args)
at Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(Application platformApplication, IApplication application, LaunchActivatedEventArgs args)
at Microsoft.Maui.MauiWinUIApplication.OnLaunched(LaunchActivatedEventArgs args)
at Microsoft.UI.Xaml.Application.Microsoft.UI.Xaml.IApplicationOverrides.OnLaunched(LaunchActivatedEventArgs args)
at ABI.Microsoft.UI.Xaml.IApplicationOverrides.Do_Abi_OnLaunched_0(IntPtr thisPtr, IntPtr args)

How to set or change active Tab UI

This library is great. I almost got the UI what I wanted.

Can you give suggestion for How to set the opacity of the active tab 1 and not active tab opacity is 0.6.

I achieve the bottom tab opacity by code. But at the top bar I couldn't get the look what I wanted.

My suggestion is to give an example of active and nonactive UI using Visual State Manager or something else without code behind.

Screenshot_1701681459

DisplayContentBehindBars

Hello.

I´m trying to use the DisplayContentBehindBars function in my app.
On IOS, the statusbar is being displayed transparent as expected.
On Android it´s being displayed WHITE.

I know your Marvelous sample and in your sample the code works on android as well. I tried to figure out if I was missing something, but didn´t find any significant difference. One thing: I´m not using your shell implementation.

Is there anything special I missed one has to do to get ir running on android?

Thanks for your help!

Java.Lang.NullPointerException: Attempt to invoke virtual method 'void android.view.animation.Animation.setStartTime(long)' on a null object reference

`Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualVoidMethod(JniObjectReference , JniObjectReference , JniMethodInfo , JniArgumentValue* )
Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualVoidMethod(String , IJavaPeerable , JniArgumentValue* )
Android.Views.View.StartAnimation(Animation )
SimpleToolkit.SimpleShell.NavigationManager.PlatformSimpleStackNavigationManager.NavigateWithPlatformTransitionToPageInContainer(SimpleShell shell, IView previousShellItemContainer, IView previousShellSectionContainer, IView previousPage, Boolean isPreviousPageRoot, Func`2 pageTransition, Func`1 args, Boolean animated)
SimpleToolkit.SimpleShell.NavigationManager.PlatformSimpleStackNavigationManager.NavigateToPage(SimpleShellTransitionType transitionType, PresentationMode presentationMode, ArgsNavigationRequest args, SimpleShell shell, IReadOnlyList`1 newPageStack, IView previousShellItemContainer, IView previousShellSectionContainer, IView previousPage, Boolean isPreviousPageRoot)
System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
Android.App.SyncContext.<>c__DisplayClass2_0.<Post>b__0()
Java.Lang.Thread.RunnableImplementor.Run()
Java.Lang.IRunnableInvoker.n_Run(IntPtr jnienv, IntPtr native__this)
Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V callback, IntPtr jnienv, IntPtr klazz)
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.animation.Animation.setStartTime(long)' on a null object reference
android.view.View.startAnimation View.java:28856
mono.java.lang.RunnableImplementor.n_run(Native Method)
mono.java.lang.RunnableImplementor.run RunnableImplementor.java:31
android.os.Handler.handleCallback Handler.java:958
android.os.Handler.dispatchMessage Handler.java:99
android.os.Looper.loopOnce Looper.java:230
android.os.Looper.loop Looper.java:319
android.app.ActivityThread.main ActivityThread.java:8893
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run RuntimeInit.java:608
com.android.internal.os.ZygoteInit.main ZygoteInit.java:1103`

SimpleToolkit.SimpleShell Version 4.1.3 or 5.0.0
SimpleToolkit.Core Version 4.0.0 or 5.0.0
Microsoft.Maui.Controls 8.0.60
Microsoft.Maui.Controls.Compatibility 8.0.60
.net maui 8.0.60 SR6 (8.0.6)

This problem appeared when I updated Visual Studio Preview for version 17.11.0
When I browse the application using the tabbar occurs a mysterious, inexplicated crash.
I'm still investigating, but it seems to have something to do with this plugin.

How to navigate from tap gesture?

i have .xaml like this:

  <Label.GestureRecognizers>
      <TapGestureRecognizer
          x:Name="tapInbox"
          Tapped="tapInbox_Tapped"
          NumberOfTapsRequired="1"/>
  </Label.GestureRecognizers>
    void tapInbox_Tapped(System.Object sender, Microsoft.Maui.Controls.TappedEventArgs e)
    {
        this.GoToAsync($"///{PageType.InboxPage}", true);
    }

and i register route like this:

Routing.RegisterRoute(nameof(PageType.InboxPage), typeof(InboxPage));

i need help because i don't know how to fix this

Swipe to go back gesture not working in iOS

Hello,

While the swipe to go back gesture works fine in Android, in iOS it's not working at all.
I am pushing the page like this from within a tab: Shell.Current.GoToAsync("route");

Is there any workaround?

PS. Congrats on this great plugin, it really brings much needed features to Shell.

Navigation Page

Hello @RadekVyM,

How to warp AppShell with Navigation Page?

For example:

MainPage = new NavigationPage(new AppShell());

when i write this code, i have an error

Multiple Navigation (page1=>page2=>page3)

Hello, I used SimpleShell. Please help me to implement a hierarchy of pages and navigate through them, that is, return to the previous page.
page1=>page2=>page3 (back to page2)
GotoAsync build in back button does not go back to previous page, when working with 3 or more

Probably Behaviors not working in Simpleshell

My xaml markup code is (code have the behavior)

<simpleShell:SimpleShell.Content>
	<Grid RowDefinitions="50, *">
		...
		<Grid x:Name="MenuContent"
			  Grid.Row="0"
			  Grid.RowSpan="2"
			  IsVisible="False">
			...
				<Grid.Behaviors>
					<IsVisibleAnimBehavior x:Name="IsVisibleAnimBehavior" ChangeVisibility="True" />
					<PositionAnimBehavior AnimationDuration="300" Easing="{x:Static Easing.BounceOut}" StartPositionX="-400" />
				</Grid.Behaviors>

			</Grid>
		</Grid>
	</Grid>
</simpleShell:SimpleShell.Content>

IsVisibleAnimBehavior behavior is responsible for triggering the animation whenever the visibility changes.

When app runs, I got exception like

System.ArgumentException: 'Unable to find IAnimationManager for 'Microsoft.Maui.Controls.Grid'. (Parameter 'animatable')'

The behavior works fine with normal Content Page.

The app crashes with SimpleShell

Hello,
I've just stumbled upon your SimpleToolkit and I wanted to implement it. It looks awesome, has some stuff that I need and also Material3 TabBar in Controls.

Right now I'm getting unhandled exception:
Java.Lang.IllegalArgumentException: 'No view found for id 0x5 (unknown) for fragment SimpleFragment{acb1dc6} (0b7617ee-9aaa-4da3-88ab-d0e65a35f48c id=0x5)'

I'm trying to follow the guide to have basic implementation for starters and I swapped everything for SimpleShell. So I'm gonna give you a tour over it.
MauiProgram.cs

using MauiApp2.Views;
using MauiApp2.ViewModels;
using Microsoft.Extensions.Logging;
using CommunityToolkit.Maui;
using Material.Components.Maui.Extensions;
using Material.Components.Maui;
using SimpleToolkit.Core;
using SimpleToolkit.SimpleShell;

namespace MauiApp2;

public static class MauiProgram
{
    public static MauiApp CreateMauiApp()
    {
        var builder = MauiApp.CreateBuilder();
        builder
            .UseMauiApp<App>()
            .UseMauiCommunityToolkit()
            //TODO .UseMaterialComponents()
            .UseSimpleShell()



            .ConfigureFonts(fonts =>
            {
                fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
            });


#if DEBUG
        builder.Logging.AddDebug();
#endif
        return builder.Build();
    }
}

App.xaml.cs

namespace MauiApp2;

public partial class App : Application
{
    public App()
    {
        InitializeComponent();

        MainPage = new AppShell();
    }
}

AppShell.xaml. I have login page route and the main one with tab bar.

<?xml version="1.0" encoding="UTF-8" ?>
<simpleShell:SimpleShell
    x:Class="MauiApp2.AppShell"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:DetailsViews="clr-namespace:MauiApp2.Views.DetailsViews"
    xmlns:Views="clr-namespace:MauiApp2.Views"
    xmlns:local="clr-namespace:MauiApp2"
    xmlns:simpleShell="clr-namespace:SimpleToolkit.SimpleShell;assembly=SimpleToolkit.SimpleShell"
    Shell.FlyoutBehavior="Disabled">





    <ShellItem FlyoutItemIsVisible="False" Route="LandingPage">
        <ShellContent ContentTemplate="{DataTemplate Views:LandingPage}" />
    </ShellItem>

    <TabBar Route="main">
        <Tab Title="Home" Icon="home.png">
            <ShellContent ContentTemplate="{DataTemplate Views:HomePage}" />
        </Tab>
        <Tab Title="Profile" Icon="user.png">
            <ShellContent ContentTemplate="{DataTemplate Views:ProfilePage}" />
        </Tab>
        <Tab Title="Anime" Icon="play_anime.png">
            <ShellContent ContentTemplate="{DataTemplate Views:AnimeListPage}" />
        </Tab>
        <Tab Title="Manga" Icon="read_manga.png">
            <ShellContent ContentTemplate="{DataTemplate Views:MangaListPage}" />
        </Tab>
        <Tab Title="Settings" Icon="settings.png">
            <ShellContent ContentTemplate="{DataTemplate Views:SettingsPage}" />
        </Tab>
    </TabBar>

</simpleShell:SimpleShell>
using MauiApp2.Views;
using MauiApp2.Views.DetailsViews;
using SimpleToolkit.SimpleShell;

namespace MauiApp2;

public partial class AppShell : SimpleToolkit.SimpleShell.SimpleShell
{
    public AppShell()
    {
        Routing.RegisterRoute("MediaDetailsPage", typeof(MediaDetailsPage));
        Routing.RegisterRoute("MediaCharacterListPage", typeof(MediaCharacterListPage));
        Routing.RegisterRoute("MediaStaffListPage", typeof(MediaStaffListPage));
        InitializeComponent();
    }
}

When I'm loading the app on that login page, it checks for token on apperance etc and goes to main route. I'm pointing this out now that I've also tried with just Shell

            if (validation)
            {
                await SimpleToolkit.SimpleShell.SimpleShell.Current.GoToAsync($"//main");
            }

This is the only Shell and navigation stuff that happens and I'm crashing. When I'm swapping everything back to Shell it will load my app. So I've need some help, because maybe I'm missing something. Are all toolkit nugets supposed to be installed on platform specific projects too? Because I didn't get an option to do so. Just the main one. Which might be the problem..

From my main project file:

<Project Sdk="Microsoft.NET.Sdk">

	<PropertyGroup>
		<TargetFrameworks>net8.0-android</TargetFrameworks>

I don't have 34 after android like in nuget requirements. But yeah it's targetting 34. I don't have 34 because the app just wouldn't start with numbera after android, after .net 8 upgrade.

Shell search handler ?

Hi does this support shell search? because when I migrate from the built-in Shell the Shell Search disappeared

Issue with Resetting MainPage in .NET MAUI

First of all, I would like to thank you for developing and sharing SimpleToolkit. I have found it to be a very useful tool for .NET MAUI development.

I am encountering an issue when trying to reset the navigation in my application. The flow of my application is as follows:

  • The user logs in from a login page.
  • Once authenticated, the user is redirected to a page with a TabBar.
  • When the user logs out, I attempt to reset the navigation so that the application returns to the login page.

To achieve this, I am using the following code in the logout method:

Application.Current.MainPage = new AppShell();

The problem occurs when I try to execute this line from another screen (for example, from a settings page or a main page). My intention is to completely reset the navigation and clear the history so that the user returns to the login screen without any trace of the previous session.

However, when executing Application.Current.MainPage = new AppShell();, I am encountering the following error:

**Java.Lang.IllegalStateException:** 'The specified child already has a parent. You must call removeView() on the child's parent first.'

**Java.Lang.IllegalStateException:** 'The specified child already has a parent. You must call removeView() on the child's parent first.'

[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: Java.Lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
[mono-rt]    at Java.Interop.JniEnvironment.InstanceMethods.CallVoidMethod(JniObjectReference instance, JniMethodInfo method, JniArgumentValue* args) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/net7.0/JniEnvironment.g.cs:line 20370
[mono-rt]    at Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualVoidMethod(String encodedMember, IJavaPeerable self, JniArgumentValue* parameters) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:line 66
[mono-rt]    at Android.Views.ViewGroup.AddView(View child) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net8.0/android-34/mcw/Android.Views.ViewGroup.cs:line 2148
[mono-rt]    at SimpleToolkit.SimpleShell.Handlers.SimpleShellHandler.UpdateContent(IView content)
[mono-rt]    at SimpleToolkit.SimpleShell.Handlers.SimpleShellHandler.MapContent(SimpleShellHandler handler, ISimpleShell shell)
[mono-rt]    at Microsoft.Maui.PropertyMapper`2.<>c__DisplayClass5_0[[SimpleToolkit.SimpleShell.ISimpleShell, SimpleToolkit.SimpleShell, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null],[SimpleToolkit.SimpleShell.Handlers.SimpleShellHandler, SimpleToolkit.SimpleShell, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null]].<Add>b__0(IElementHandler h, IElement v) in D:\a\_work\1\s\src\Core\src\PropertyMapper.cs:line 172
[mono-rt]    at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView) in D:\a\_work\1\s\src\Core\src\PropertyMapper.cs:line 47
[mono-rt]    at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView) in D:\a\_work\1\s\src\Core\src\PropertyMapper.cs:line 82
[mono-rt]    at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view) in D:\a\_work\1\s\src\Core\src\Handlers\Element\ElementHandler.cs:line 79
[mono-rt]    at Microsoft.Maui.Handlers.ViewHandler`2[[SimpleToolkit.SimpleShell.ISimpleShell, SimpleToolkit.SimpleShell, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null],[Android.Views.ViewGroup, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]].SetVirtualView(IView view) in D:\a\_work\1\s\src\Core\src\Handlers\View\ViewHandlerOfT.cs:line 53
[mono-rt]    at Microsoft.Maui.Handlers.ViewHandler`2[[SimpleToolkit.SimpleShell.ISimpleShell, SimpleToolkit.SimpleShell, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null],[Android.Views.ViewGroup, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]].SetVirtualView(IElement view) in D:\a\_work\1\s\src\Core\src\Handlers\View\ViewHandlerOfT.cs:line 56
[mono-rt]    at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler) in D:\a\_work\1\s\src\Controls\src\Core\Element\Element.cs:line 922
[mono-rt]    at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value) in D:\a\_work\1\s\src\Controls\src\Core\Element\Element.cs:line 864
[mono-rt]    at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value) in D:\a\_work\1\s\src\Controls\src\Core\VisualElement\VisualElement.cs:line 2061
[mono-rt]    at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context) in D:\a\_work\1\s\src\Core\src\Platform\ElementExtensions.cs:line 96
[mono-rt]    at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context) in D:\a\_work\1\s\src\Core\src\Platform\ElementExtensions.cs:line 127
[mono-rt]    at Microsoft.Maui.Platform.ContainerView.SetView(IElement view, Boolean forceRefresh) in D:\a\_work\1\s\src\Core\src\Platform\Android\ContainerView.cs:line 76
[mono-rt]    at Microsoft.Maui.Platform.ContainerView.set_CurrentView(IElement value) in D:\a\_work\1\s\src\Core\src\Platform\Android\ContainerView.cs:line 55
[mono-rt]    at Microsoft.Maui.Platform.ElementExtensions.ToContainerView(IElement view, IMauiContext context) in D:\a\_work\1\s\src\Core\src\Platform\Android\ElementExtensions.cs:line 11
[mono-rt]    at Microsoft.Maui.Platform.NavigationRootManager.Connect(IView view, IMauiContext mauiContext) in D:\a\_work\1\s\src\Core\src\Platform\Android\Navigation\NavigationRootManager.cs:line 56
[mono-rt]    at Microsoft.Maui.Handlers.WindowHandler.CreateRootViewFromContent(IWindowHandler handler, IWindow window) in D:\a\_work\1\s\src\Core\src\Handlers\Window\WindowHandler.Android.cs:line 91
[mono-rt]    at Microsoft.Maui.Handlers.WindowHandler.MapContent(IWindowHandler handler, IWindow window) in D:\a\_work\1\s\src\Core\src\Handlers\Window\WindowHandler.Android.cs:line 27
[mono-rt]    at Microsoft.Maui.PropertyMapper`2.<>c__DisplayClass5_0[[Microsoft.Maui.IWindow, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Handlers.IWindowHandler, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].<Add>b__0(IElementHandler h, IElement v) in D:\a\_

I would appreciate any insights or guidance on resolving this issue. My intention is to completely reset the navigation and clear the history, ensuring the user returns to the login screen without any traces of the previous session.

Thank you once again for your contribution to the community and for your assistance in this matter.

Make animation optional

Feature request: Just as you can dismiss a popover without animation on iOS using dismiss(animated:completion:), it would be useful to hide the MAUI Popover without animation. (In my use case, I want to immediately navigate to another page.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.