footerwinui-3navigationview

WinUi 3 How to fix NavigationView expanding footer item behaviour


The NavigationView expanding footer item behaviour in WinUi 3 is bugged. The footer panel is not resized when an item is expanded and part of the footer is not visible (you can scrool the footer panel).


Solution

  • Add events to NavigationView

    <NavigationView
        ...
        Collapsed="NavigationViewControl_Collapsed"
        Expanding="NavigationViewControl_Expanding"
        ... 
    >
    

    To redraw NavigationView you need to change it's layout or the window size. I have found that changing the margin is the least invasive:

    private void NavigationViewControl_Expanding(NavigationView sender, NavigationViewItemExpandingEventArgs args)
    {
        /* To fix NavigationView footer menu item expanding behaviour */
        var item = args.ExpandingItem as NavigationViewItem;
        if(sender.FooterMenuItems.Contains(item))
        {
            if(sender.Margin.Bottom > 0)
            {
                sender.Margin = new(0, 0, 0, 0);
            }
            else
            {
                sender.Margin = new(0, 0, 0, 1);
            }            
        }
    }
    
    private void NavigationViewControl_Collapsed(NavigationView sender, NavigationViewItemCollapsedEventArgs args)
    {
        /* To fix NavigationView footer menu item expanding behaviour */
        var item = args.CollapsedItem as NavigationViewItem;
        if (sender.FooterMenuItems.Contains(item))
        {
            if (sender.Margin.Bottom > 0)
            {
                sender.Margin = new(0, 0, 0, 0);
            }
            else
            {
                sender.Margin = new(0, 0, 0, 1);
            }
        }
    }