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 8 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 MainViewModel();

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 MainViewModel
Copy link
Contributor

Choose a reason for hiding this comment

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

The build is failing:

D:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Issues\Issue25191.xaml.cs(15,15): error CS0101: The namespace 'Maui.Controls.Sample.Issues' already contains a definition for 'MainViewModel' [D:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Controls.TestCases.HostApp.csproj::TargetFramework=net9.0-tizen]
D:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Issues\Issue25191.xaml.cs(15,15): error CS0101: The namespace 'Maui.Controls.Sample.Issues' already contains a definition for 'MainViewModel' [D:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Controls.TestCases.HostApp.csproj::TargetFramework=net9.0-windows10.0.20348.0]
    6924 Warning(s)
    6 Error(s)

Another sample is already using a MainViewModel, my recommendation here is always use the issue id to create view models etc. For example: Issue21112ViewModel or Issue21112MainView etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated the code based on your feedback. Could you please review it and let me know if there are any further concerns

{
public ICommand NavigateCommand { get; set; }

public MainViewModel()
{
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