Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/Controls/src/Core/Handlers/Shell/ShellItemHandler.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,15 @@ private void OnNavigationTabChanged(NavigationView sender, NavigationViewSelecti

((Shell)VirtualView.Parent).CurrentItem = shellSection;
}
else if (selectedItem.Data is ShellContent shellContent)
else if (selectedItem.Data is ShellContent shellContent && VirtualView.Parent is Shell parentShell)
{
((Shell)VirtualView.Parent).CurrentItem = shellContent;
// We need to invoke ProposeSection for TabBar items navigation for ShellContent
var currentItem = parentShell.CurrentItem?.CurrentItem;
if (currentItem?.Title != shellContent.Title && currentItem != shellContent.Parent)
{
(parentShell.CurrentItem as IShellItemController)?.ProposeSection(shellContent);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anywhere else we can call this so that the user can cancel the navigation?

The point of ProposeSection is to give the user time to cancel the navigation

Copy link
Copy Markdown
Contributor Author

@SuthiYuvaraj SuthiYuvaraj Mar 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @PureWeen ,

This issue is commonly observed in tab navigation and has not worked in previous cases. I have attached the relevant non-working scenarios, and a separate issue report (#28539) has been created for further investigation.

 

Navigation Type Status
TabBar – Tab – ShellContent Navigating triggered without our fix , not able to cancel
TabBar – ShellContent Navigating triggered  after fix, not able to cancel
FlyoutItem – ShellContent Navigating triggered after fix , not able to cancel

}
parentShell.CurrentItem = shellContent;
}
}

Expand Down
113 changes: 113 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue12500.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
using System.ComponentModel;
using Maui.Controls.Sample.Issues;
using Microsoft.Maui;
using Microsoft.Maui.Controls;

namespace Controls.TestCases.Issues;

[Issue(IssueTracker.Github, 12500, "Shell does not always raise Navigating event on Windows", PlatformAffected.UWP)]
public class Issue12500 : Shell
{
private NavigationViewModel _viewModel;
public Issue12500()
{
this.FlyoutBehavior = FlyoutBehavior.Disabled;

_viewModel = new NavigationViewModel();

// Create TabBar
var tabBar = new TabBar();

// Add ShellContent for MainPage
tabBar.Items.Add(new ShellContent
{
Title = "Hello, World!",
Route = "MainPage",
ContentTemplate = new DataTemplate(() => new Issue12500Main { BindingContext = _viewModel })
});
// Add ShellContent for EventsPage
tabBar.Items.Add(new ShellContent
{
Title = "Events",
Route = "EventPage",
ContentTemplate = new DataTemplate(() => new Issue12500EventPage { BindingContext = _viewModel })
});

// Add TabBar to Shell
this.Items.Add(tabBar);
}
protected override void OnNavigating(ShellNavigatingEventArgs args)
{
base.OnNavigating(args);
string targetPageRoute = args.Target.Location.ToString();

// Update ViewModel with new navigation text
_viewModel.LabelText = $"Navigating to {targetPageRoute}";

}
}
public class Issue12500EventPage : ContentPage
{
public Issue12500EventPage()
{
var label = new Label
{
AutomationId = "Issue12500EventPage",
FontSize = 24,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
};
label.SetBinding(Label.TextProperty, nameof(NavigationViewModel.LabelText)); // Bind to ViewModel

Content = new VerticalStackLayout
{
Children = { label }
};
}
}

public class Issue12500Main : ContentPage
{
public Issue12500Main()
{
var label = new Label
{
AutomationId = "Issue12500MainPage",
FontSize = 24,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
};
label.SetBinding(Label.TextProperty, nameof(NavigationViewModel.LabelText)); // Bind to ViewModel

Content = new VerticalStackLayout
{
Children = { label }
};
}
}


public class NavigationViewModel : INotifyPropertyChanged
{
private string _labelText;

public string LabelText
{
get => _labelText;
set
{
if (_labelText != value)
{
_labelText = value;
OnPropertyChanged(nameof(LabelText));
}
}
}

public event PropertyChangedEventHandler PropertyChanged;

protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue12500 : _IssuesUITest
{
public override string Issue => "Shell does not always raise Navigating event on Windows";

public Issue12500(TestDevice device) : base(device)
{
}

[Test]
[Category(UITestCategories.Shell)]
public void ShellNavigatingShouldTrigger()
{
App.WaitForElement("Issue12500MainPage");
App.WaitForElement("Events");
App.Tap("Events");
var result = App.WaitForElement("Issue12500EventPage").GetText();
Assert.That(result, Is.EqualTo("Navigating to //EventPage"));
}
}
Loading