dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.99k stars 1.72k forks source link

BottomNavigationView ItemSelected EventHandler #23942

Closed nvgogh closed 1 month ago

nvgogh commented 1 month ago

Description

I have the following handler

class ShellBottomNavViewAppearanceTrackerEx : ShellBottomNavViewAppearanceTracker
{
    IShellContext _shellContext;
    private readonly ShellItem _shellItem;
    bool handlerset = false;

    public ShellBottomNavViewAppearanceTrackerEx(IShellContext shellContext, ShellItem shellItem) : base(shellContext, shellItem)
    {
        _shellContext = shellContext;
        _shellItem = shellItem;
    }

    public override void SetAppearance(BottomNavigationView bottomView, IShellAppearanceElement appearance)
    {
        base.SetAppearance(bottomView, appearance);

        if (!handlerset)
        {
            handlerset = true;
            bottomView.ItemSelected += IconSelected;
        }
    }

    private void IconSelected(object? sender, EventArgs e)
    {
        // Do Something
    }
}

The EventHandler IconSelected gets called. However then the tab page change no longer happens. Am I missing something? If I remove the add of the eventhandler line then the tab is switching again. It almost feels like it's not combining any eventhandler which are already bound with this new one.

Steps to Reproduce

Use the above handler

Link to public reproduction project repository

No response

Version with bug

8.0.70 SR7

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

jfversluis commented 1 month ago

@PureWeen ?

nvgogh commented 1 month ago

I found an alternative that also works for me.

I overwrote the CreateShellItemRenderer to create a custom ShellItemRenderer on which the function OnItemSelected can be overwritten.