Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a4182b5
Fixed IsEnabled Property is not works for Tab
Dhivya-SF4094 Dec 19, 2024
05bc470
Modified Test case and Optimized code for runtime changes for WinUI
Dhivya-SF4094 Dec 19, 2024
33e4142
Removed AndExpand in test samples
Dhivya-SF4094 Dec 20, 2024
1b08d25
Modified test cases
Dhivya-SF4094 Dec 20, 2024
325c21e
Revert "Modified test cases"
Dhivya-SF4094 Dec 20, 2024
7d82314
Modified test case to apply runtime changes
Dhivya-SF4094 Dec 20, 2024
70454e6
Changed test case naming
Dhivya-SF4094 Dec 20, 2024
f51b2af
Fixed CI failure in Android and WinUI
Dhivya-SF4094 Dec 24, 2024
8db864d
Updated namespace
Dhivya-SF4094 Jan 2, 2025
86ef626
Updated indentation in testcase sample
Dhivya-SF4094 Jan 3, 2025
6a99f63
Updated the code as loop starts from 0
Dhivya-SF4094 Jan 10, 2025
b8de19e
Fixed IsEnabled Property is not works for Tab
Dhivya-SF4094 Dec 19, 2024
45d6a49
Modified Test case and Optimized code for runtime changes for WinUI
Dhivya-SF4094 Dec 19, 2024
8a46930
Modified test cases
Dhivya-SF4094 Dec 20, 2024
70c94c7
Revert "Modified test cases"
Dhivya-SF4094 Dec 20, 2024
3f48328
Updated the code as loop starts from 0
Dhivya-SF4094 Jan 10, 2025
94fa4bb
Removed unwanted keyword
Dhivya-SF4094 Feb 5, 2025
b55e98d
Included the removed test sample
Dhivya-SF4094 Jul 14, 2025
23ac384
Updated ShellItemHandler.Windows
Dhivya-SF4094 Jul 14, 2025
e9f188a
Fixed CI failure
Dhivya-SF4094 Jul 15, 2025
131219b
Fixed CI failure for windows platform
Dhivya-SF4094 Jul 17, 2025
8f70cce
Reverted iOS fix; already addressed in PR #33369.
Dhivya-SF4094 Feb 23, 2026
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
43 changes: 40 additions & 3 deletions src/Controls/src/Core/Handlers/Shell/ShellItemHandler.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,19 @@ protected override void DisconnectHandler(FrameworkElement platformView)
}

if (_shellItem is IShellItemController shellItemController)
{
shellItemController.ItemsCollectionChanged -= OnItemsChanged;

if (VirtualView.Parent is Shell shell)
{
shell.Navigated -= OnShellNavigated;
if (VirtualView.Parent is Shell shell)
{
shell.Navigated -= OnShellNavigated;
}

foreach (var item in shellItemController.GetItems())
{
item.PropertyChanged -= OnShellItemPropertyChanged;
}

}
}

Expand Down Expand Up @@ -203,6 +211,7 @@ internal void MapMenuItems()

foreach (var item in shellItemController.GetItems())
{
item.PropertyChanged += OnShellItemPropertyChanged;
if (Routing.IsImplicit(item))
items.Add(item.CurrentItem);
else
Expand Down Expand Up @@ -254,6 +263,7 @@ internal void MapMenuItems()
void SetValues(BaseShellItem bsi, NavigationViewItemViewModel vm)
{
vm.Content = bsi.Title;
vm.IsEnabled = bsi.IsEnabled;
var iconSource = bsi.Icon?.ToIconSource(MauiContext!);

if (iconSource != null)
Expand Down Expand Up @@ -409,6 +419,33 @@ void OnSearchBoxQuerySubmitted(Microsoft.UI.Xaml.Controls.AutoSuggestBox sender,
}
}

void OnShellItemPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (_mainLevelTabs == null || sender is not BaseShellItem shellItem)
{
return;
}

for (int i = 0; i < _mainLevelTabs.Count; i++)
{
if (_mainLevelTabs[i].Data != sender)
{
continue;
}

switch (e.PropertyName)
{
case nameof(BaseShellItem.IsEnabled):
_mainLevelTabs[i].IsEnabled = shellItem.IsEnabled;
break;
case nameof(BaseShellItem.Title):
_mainLevelTabs[i].Content = shellItem.Title;
break;
}
return;
}
}

void OnCurrentSearchHandlerPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (_currentSearchHandler is null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
x:Name="navViewItem"
Content="{Binding Content}"
Background="{Binding Background}"
IsEnabled="{Binding IsEnabled}"
IsSelected="{Binding IsSelected, Mode=TwoWay}"
MenuItemsSource="{Binding MenuItemsSource}"
Icon="{Binding Icon}"
Expand Down
1 change: 1 addition & 0 deletions src/Controls/src/Core/TabbedPage/TabbedPage.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ internal static void MapItemsSource(ITabbedViewHandler handler, TabbedPage view)
vm.SelectedForeground = view.SelectedTabColor?.AsPaint()?.ToPlatform();
vm.UnselectedForeground = view.UnselectedTabColor?.AsPaint()?.ToPlatform();
vm.IsSelected = page == view.CurrentPage;
vm.IsEnabled = page.IsEnabled;
});

handler.UpdateValue(nameof(TabbedPage.CurrentPage));
Expand Down
133 changes: 133 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue5161.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
using System;
using Microsoft.Maui.Controls;

namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 5161, "ShellContent IsEnabledProperty does not work", PlatformAffected.iOS)]
public class Issue5161 : Shell
{
public Issue5161()
{
var mainPageTab = new Tab
{
Title = "FirstPage",
IsEnabled = true,
};
mainPageTab.Items.Add(new ShellContent
{
ContentTemplate = new DataTemplate(() => new Issue5161_MainPage())
});

var secondPageTab = new Tab
{
Title = "SecondTab",
IsEnabled = false,
AutomationId = "SecondTab"
};
secondPageTab.Items.Add(new ShellContent
{
ContentTemplate = new DataTemplate(() => new SecondPage())
});
var thirdTab = new Tab
{
Title = "ThirdTab",
IsEnabled = true,
AutomationId = "ThirdTab"
};
thirdTab.Items.Add(new ShellContent
{
ContentTemplate = new DataTemplate(() => new ThirdPage())
});
var tabBar = new TabBar();
tabBar.Items.Add(mainPageTab);
tabBar.Items.Add(secondPageTab);
tabBar.Items.Add(thirdTab);
Items.Add(tabBar);
}

public class Issue5161_MainPage : ContentPage
{
public Issue5161_MainPage()
{
Content = new StackLayout
{
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
Children =
{
new Label
{
Text = "This is First Page",
}
}
};
}
}

public class SecondPage : ContentPage
{
public SecondPage()
{
Content = new StackLayout
{
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
Children =
{
new Label
{
Text = "This is Second Page",
AutomationId = "SecondPageLabel"
}
}
};
}
}
public class ThirdPage : ContentPage
{
public ThirdPage()
{
var label = new Label
{
Text = "This is Third Page",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
AutomationId = "ThirdPageLabel"
};

var button = new Button
{
Text = "Enable SecondTab",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
AutomationId = "EnableSecondTab"
};
button.Clicked += OnButtonClicked;
Content = new StackLayout
{
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
Children =
{
label,
button
}
};
}

private void OnButtonClicked(object sender, EventArgs e)
{
if (Application.Current?.Windows.Count > 0 &&
Application.Current.Windows[0].Page is Shell shell)
{
var secondTab = shell.CurrentItem?.Items[1];
if (secondTab is not null)
secondTab.IsEnabled = true;
}
else
{
System.Diagnostics.Debug.WriteLine("Shell not found!");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue5161 : _IssuesUITest
{
public Issue5161(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "ShellContent IsEnabledProperty does not work";

[Test]
[Category(UITestCategories.Shell)]
public void CheckIsEnabled()
{
App.WaitForElement("ThirdTab");
App.Tap("ThirdTab");
App.WaitForElement("ThirdPageLabel");
App.Tap("SecondTab");
App.WaitForNoElement("SecondPageLabel");
App.Tap("EnableSecondTab");
App.Tap("SecondTab");
App.WaitForElement("SecondPageLabel");
}
}
13 changes: 13 additions & 0 deletions src/Core/src/Platform/Windows/NavigationViewItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ internal class NavigationViewItemViewModel : INotifyPropertyChanged

object? _content;
bool _isSelected;
bool _isEnabled;
WBrush? _selectedBackground;
WBrush? _unselectedBackground;
WBrush? _selectedForeground;
Expand Down Expand Up @@ -232,6 +233,18 @@ public bool IsSelected
}
}

public bool IsEnabled
{
get => _isEnabled;
set
{
if (_isEnabled != value)
{
_isEnabled = value;
OnPropertyChanged(nameof(IsEnabled));
}
}
}
void OnPropertyChanged(string args) =>
OnPropertyChanged(new PropertyChangedEventArgs(args));

Expand Down
Loading