Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling Clicks From PaneFooter Items in NavigationView UWP

I'm currently working on a UWP app and I have this <NavigationView> that handles <NavigationViewItem> clicks in the <NavigationView.MenuItems>. It seems not to recognise <NavigationViewItem> clicks in the <NavigationView.PaneFooter>.

This is the XAML code

<NavigationView x:Name="ControlNavigationView" Margin="0,0,0,0" IsSettingsVisible="False" Header="Welcome" SelectionChanged="NavigationView_SelectionChanged">
            <NavigationView.MenuItems>
                <NavigationViewItem Icon="OtherUser" Content="Positions" Tag="Positions"/>
                <NavigationViewItem Icon="People" Content="Workers" Tag="Workers"/>
                <NavigationViewItem Icon="Phone" Content="Customers" Tag="Customers"/>
                <NavigationViewItem Icon="Manage" Content="Materials" Tag="Materials"/>
                <NavigationViewItem Content="Flies" Tag="Flies">
                    <NavigationViewItem.Icon>
                        <FontIcon Glyph="&#xE24A;"/>
                    </NavigationViewItem.Icon>
                </NavigationViewItem>
                <NavigationViewItem Icon="Shop" Content="Orders" Tag="Orders"/>
                <NavigationViewItem Icon="Library" Content="Job Cards" Tag="Job Cards"/>
            </NavigationView.MenuItems>
            <NavigationView.PaneFooter>
                <NavigationViewItem Icon="Contact" Content="User" Tag="User"/>
            </NavigationView.PaneFooter>
            <Frame x:Name="ContentFrame">
                <Frame.ContentTransitions>
                    <TransitionCollection>
                        <NavigationThemeTransition/>
                    </TransitionCollection>
                </Frame.ContentTransitions>
            </Frame>
        </NavigationView>

The C# Code

private void NavigationView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
    {
        switch (((NavigationViewItem)args.SelectedItem).Tag.ToString())
        {
            case "Positions":
                ContentFrame.Navigate(typeof(UnderConstructionPage), ((NavigationViewItem)args.SelectedItem).Tag.ToString());
                ControlNavigationView.Header = ((NavigationViewItem)args.SelectedItem).Tag.ToString();
                break;
            case "Workers":
                ContentFrame.Navigate(typeof(UnderConstructionPage), ((NavigationViewItem)args.SelectedItem).Tag.ToString());
                ControlNavigationView.Header = ((NavigationViewItem)args.SelectedItem).Tag.ToString();
                break;
            case "Customers":
                ContentFrame.Navigate(typeof(UnderConstructionPage), ((NavigationViewItem)args.SelectedItem).Tag.ToString());
                ControlNavigationView.Header = ((NavigationViewItem)args.SelectedItem).Tag.ToString();
                break;
            case "Materials":
                ContentFrame.Navigate(typeof(UnderConstructionPage), ((NavigationViewItem)args.SelectedItem).Tag.ToString());
                ControlNavigationView.Header = ((NavigationViewItem)args.SelectedItem).Tag.ToString();
                break;
            case "Flies":
                ContentFrame.Navigate(typeof(UnderConstructionPage), ((NavigationViewItem)args.SelectedItem).Tag.ToString());
                ControlNavigationView.Header = ((NavigationViewItem)args.SelectedItem).Tag.ToString();
                break;
            case "Orders":
                ContentFrame.Navigate(typeof(UnderConstructionPage), ((NavigationViewItem)args.SelectedItem).Tag.ToString());
                ControlNavigationView.Header = ((NavigationViewItem)args.SelectedItem).Tag.ToString();
                break;
            case "Job Cards":
                ContentFrame.Navigate(typeof(UnderConstructionPage), ((NavigationViewItem)args.SelectedItem).Tag.ToString());
                ControlNavigationView.Header = ((NavigationViewItem)args.SelectedItem).Tag.ToString();
                break;
            case "User":
                ContentFrame.Navigate(typeof(UnderConstructionPage), ((NavigationViewItem)args.SelectedItem).Tag.ToString());
                ControlNavigationView.Header = ((NavigationViewItem)args.SelectedItem).Tag.ToString();
                break;
        }
    }

How do i handle a click event on

<NavigationView.PaneFooter>
            <NavigationViewItem Icon="Contact" Content="User" Tag="User"/>
</NavigationView.PaneFooter>
like image 565
Timothy Oliver Avatar asked Jul 07 '18 20:07

Timothy Oliver


1 Answers

It's by design. The SelectionChanged event will be fired only when the currently selected item changes in the menu.

In your case, you could register Tap event for this NavigationViewItem like the following:

<NavigationView.PaneFooter>
        <NavigationViewItem Icon="Contact" Content="User" Tag="User" Tapped="NavigationViewItem_Tapped"/>
</NavigationView.PaneFooter>
private void NavigationViewItem_Tapped(object sender, TappedRoutedEventArgs e)
{
    NavigationViewItem navigationViewItem = sender as NavigationViewItem;
    ContentFrame.Navigate(typeof(UnderConstructionPage), navigationViewItem.Tag);
    ControlNavigationView.Header = navigationViewItem.Tag;
}
like image 190
Xie Steven Avatar answered Oct 02 '22 14:10

Xie Steven