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:
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
2.4.2
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
2.4.2
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
@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.
Most helpful comment
Yep, I have a fix in the works. This is a symptom of a deeper underlying bug for this scenario.