Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Fixed TextCell Command executes only once #25066

Merged
merged 9 commits into from
Oct 30, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ void OnUnloaded(object sender, RoutedEventArgs e)
// 🚀 unsubscribe from propertychanged
Cell.PropertyChanged -= _propertyChangedHandler;
// Allows the Cell to unsubscribe from Parent.PropertyChanged
Cell.Parent = null;
if (Cell.Parent is ListView)
Cell.Parent = null;
}


Expand Down
111 changes: 111 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue21112.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
using System.Windows.Input;

namespace Maui.Controls.Sample.Issues
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 21112, "TableView TextCell command executes only once", PlatformAffected.UWP)]
public class Issue21112 : NavigationPage
{
public Issue21112() : base(new MainPage())
{

}
}

public class MainPage : ContentPage
{
public MainPage()
{
var stackLayout = new StackLayout();
BindingContext = new Issue21112ViewModel();

var headerTextCell = new TextCell
{
Text = "Header demo",
Detail = "Absolute positioning and sizing"
};

headerTextCell.SetBinding(TextCell.CommandProperty, new Binding("NavigateCommand"));
headerTextCell.CommandParameter = typeof(DemoPage);

var tableView = new TableView
{
Intent = TableIntent.Menu,
Root = new TableRoot
{
new TableSection("XAML")
{
headerTextCell
}
}
};

var button = new Button
{
Text = "Trigger TextCell Click",
AutomationId = "MainPageButton"
};

button.Clicked += (sender, e) =>
{
headerTextCell.Command.Execute(headerTextCell.CommandParameter);
};

stackLayout.Children.Add(tableView);
stackLayout.Children.Add(button);

Content = stackLayout;
}
}

public partial class DemoPage : ContentPage
{
public DemoPage()
{
Title = "Text demo";

var button = new Button
{
AutomationId = "NavigatedPageButton",
Text = "Click"
};

var label = new Label
{
AutomationId = "NavigatedPageLabel",
Text = "Main Page"
};

button.Clicked += (sender, e) =>
{
Navigation.PopAsync();
};

Content = new StackLayout
{
Children =
{
button,
label
}
};
}
}

public class Issue21112ViewModel
{
public ICommand NavigateCommand { get; set; }

public Issue21112ViewModel()
{
NavigateCommand = new Command<Type>(async (Type pageType) =>
{
Page page = Activator.CreateInstance(pageType) as Page;
if (page is not null)
{
await Application.Current.MainPage.Navigation.PushAsync(page);
}
});
}
}
}
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 Issue21112 : _IssuesUITest
{
public Issue21112(TestDevice testDevice) : base(testDevice)
{
}
public override string Issue => "TableView TextCell command executes only once";

[Test]
[Category(UITestCategories.TableView)]
public void TableViewTextCellCommand()
{
App.WaitForElement("MainPageButton");
App.Tap("MainPageButton");
App.WaitForElement("NavigatedPageButton");
App.Tap("NavigatedPageButton");
App.WaitForElement("MainPageButton");
App.Tap("MainPageButton");
var label = App.WaitForElement("NavigatedPageLabel");
Assert.That(label.GetText(), Is.EqualTo("Main Page"));
}
}
}
Loading