Microsoft-ui-xaml: NavigationView in 2.4 doesn't return the Item anymore in ItemInvoked

Created on 21 May 2020  ·  4Comments  ·  Source: microsoft/microsoft-ui-xaml

Describe the bug
The 2.4 release broke the ItemInvoked API contract by returning the realized UI Element from the new underlying ItemsRepeater _instead of_ the Item from the underlying MenuItemsSource collection.

Steps to reproduce the bug

Sample Code

    <Page.Resources>
        <DataTemplate x:Key="CategoryTemplate"
                      x:DataType="local:SampleCategory">
            <Grid>
                <TextBlock VerticalAlignment="Center"
                           FontFamily="Segoe UI"
                           FontSize="15px"
                           FontWeight="Normal"
                           Text="{x:Bind Name}" />
            </Grid>
        </DataTemplate>
    </Page.Resources>

    <winui:NavigationView x:Name="NavView"
                          PaneDisplayMode="Top"
                          MenuItemTemplate="{StaticResource CategoryTemplate}"
                          ItemInvoked="NavView_ItemInvoked"
                          SelectionFollowsFocus="Disabled"
                          IsSettingsVisible="True"/>

Code Behind

        private List<SampleCategory> sampleCategories = new List<SampleCategory>()
        {
            new SampleCategory()
            {
                Name = "Controls",
                Samples = new Sample[] {
                    new Sample()
                    {
                        Name = "UniformGrid",
                        Subcategory = "Panels",
                        About = "Some Info...",
                    },
                    new Sample()
                    {
                        Name = "WrapPanel",
                        Subcategory = "Panels",
                        About = "Some Info...",
                    }
                }
            },
            new SampleCategory()
            {
                Name = "Extensions",
                Samples = new Sample[] {
                    new Sample()
                    {
                        Name = "Mouse",
                        About = "Some Info...",
                    },
                    new Sample()
                    {
                        Name = "OnDevice",
                        About = "Some Info...",
                    }
                }
            }
        };

        public MainPage()
        {
            this.InitializeComponent();

            NavView.MenuItemsSource = sampleCategories;
        }



Steps to reproduce the behavior:

  1. Open sample (or re-create from pasted code below)
  2. Run sample
  3. Click on 'Controls' item in NavigationView
  4. Should see message dialog from our working 2.3.x code (but don't)
  5. Note: that we don't get the same result between the previous package and 2.4, this breaks apps trying to upgrade!

See the 2.3.200213001 branch on the same repo. You can switch to that which has the previous NuGet package setup to see the difference in behavior.

Actual behavior
NavigationViewItemInvokedEventArgs.ItemInvoked is a UIElement of the realized data template.

Expected behavior
Should return the underlying Item in the args from the MenuItemsSource (as it did before in 2.3).

Screenshots

Item Invoked for Item (Controls):

  • 2.3.200213001
    image

  • 2.4.2
    image
    Note: Here we're not getting our item as we'd expect!

Item Invoked for Settings (this looks the same and seems fine, but adding for completeness)

  • 2.3.200213001
    image

  • 2.4.2
    image

Version Info

NuGet package version: Microsoft.UI.Xaml 2.4.2

| Windows 10 version | Saw the problem? |
| :--------------------------------- | :-------------------- |
| Insider Build (xxxxx) | |
| May 2020 Update (19041) | Yes |
| November 2019 Update (18363) | |
| May 2019 Update (18362) | |
| October 2018 Update (17763) | |
| April 2018 Update (17134) | |
| Fall Creators Update (16299) | |
| Creators Update (15063) | |


| Device form factor | Saw the problem? |
| :-------------------- | :------------------- |
| Desktop | Yes |
| Mobile | |
| Xbox | |
| Surface Hub | |
| IoT | |

Additional context

area-NavigationView team-Controls

Most helpful comment

Are you looking into this right now

Yep, I have a fix in the works. This is a symptom of a deeper underlying bug for this scenario.

All 4 comments

@ojhad can you investigate this issue ?

@ojhad @ranjeshj is this fixed in the new 2.5 prerelease package?

This is a regression and breaking change to anyone using this event on NavigationView updating to 2.4.x, so will it be patched in the 2.4 line as well?

I don't think there has been a fix for this yet.

@ojhad Are you looking into this right now or would you like me to look into this/mind me looking into this? CC @ranjeshj

Are you looking into this right now

Yep, I have a fix in the works. This is a symptom of a deeper underlying bug for this scenario.

Was this page helpful?
0 / 5 - 0 ratings