简体   繁体   中英

UNO Material BottomNavigationBar Event Handler

I am implementing the BottomNavigationBar from Uno.Material in my app. I can get the bar to appear like I want it to- but can not figure out what the event handler is for when I click on a bottomnavigationbaritem to change it. I have tried ItemInvoked, OnPressed, OnTouch, OnClick, Clicked- but not able to get it to work. I am a bit embarrassed to ask- but would someone be able to point me in the right direction of what event is fired and what the method signature of the event should be?

... <controls:BottomNavigationBar x:Name="BottomNavBar" Grid.Row="2"mOnClick="BottomNavView_ItemInvoked"> ...

BottomNavigationBar does not expose an ItemInvoked event. You can retrieve the current selection via the SelectedItem property. I suppose it could also offer a ItemInvoked option like NavigationView is offering, feel free to open an issue here with your suggestion.

However, BottomNavigationBarItem is a ToggleButton , so it implements the Click , Checked and Unchecked events already.

Here's an example of how you could handle those events in your app. (You probably only need Checked , depending on your scenario)

<controls:BottomNavigationBar>
    <controls:BottomNavigationBar.Items>

        <controls:BottomNavigationBarItem Label="Favorites"
                                          Click="OnClick"
                                          Checked="OnChecked"
                                          Unchecked="OnUnChecked">
            <controls:BottomNavigationBarItem.Icon>
                <SymbolIcon Symbol="Favorite" />
            </controls:BottomNavigationBarItem.Icon>
        </controls:BottomNavigationBarItem>
[...insert more items...]
    </controls:BottomNavigationBar.Items>
</controls:BottomNavigationBar>
public void OnClick(object sender, object args)
{
    var navBarItem = sender as BottomNavigationBarItem;

    // Add logic here
}

public void OnChecked(object sender, object args)
{
    var navBarItem = sender as BottomNavigationBarItem;

    // Add logic here
}

public void OnUnChecked(object sender, object args)
{
    // Items are automatically unchecked when another one is checked.
    var navBarItem = sender as BottomNavigationBarItem;

    // Add logic here
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM