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

[WinUI] Command on TableView only invokes once. #25037

Closed
mthanson8333 opened this issue Oct 1, 2024 · 4 comments
Closed

[WinUI] Command on TableView only invokes once. #25037

mthanson8333 opened this issue Oct 1, 2024 · 4 comments
Labels
area-controls-listview ListView and TableView platform/windows 🪟 t/bug Something isn't working

Comments

@mthanson8333
Copy link

mthanson8333 commented Oct 1, 2024

Description

Downloaded sample code from https://github.com/dotnet/maui-samples/tree/main/8.0/UserInterface/Views/CollectionViewDemos. Tried to run CollectionView sample code under Windows emulator and the menu on the MainPage did not work as expected. Under windows when the app starts I click a menu item and are taken to the proper page. When I return to menu and click on another menu item, nothing happens. This happens under Windows emulator. On Android app works as expected. Not building for Apple. I checked community and the closes article I found #2003 did not answer my question.

Steps to Reproduce

  1. Download source code from https://github.com/dotnet/maui-samples/tree/main/8.0/UserInterface/Views/CollectionViewDemos.
  2. Compile and run code under Windows emulator.
  3. Click on a menu item. You will be taken to the proper page.
  4. Return to menu and click on other menu items. Nothing happens

Link to public reproduction project repository

https://github.com/dotnet/maui-samples/tree/main/8.0/UserInterface/Views/CollectionViewDemos

Version with bug

8.0.82 SR8.2

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

Windows 11 version 22631.4249

Did you find any workaround?

Yes. MainPage.Xaml

<ListView ItemsSource="{x:Static local:PageDataViewModel.All}"
              ItemSelected="OnListViewItemSelected"
              HasUnevenRows="True">
		<!-- Allow rows to adjust height based on content -->
		<ListView.ItemTemplate>
			<DataTemplate>
				<ViewCell>
					<Frame Margin="0,0,0,10" Padding="0" HasShadow="False" BorderColor="Transparent">
						<StackLayout>
							<Label Text="{Binding Title}" FontSize="Medium" VerticalOptions="Start" />
							<Label Text="{Binding Description}" FontSize="Small" TextColor="Gray" LineBreakMode="WordWrap" VerticalOptions="Start" />
						</StackLayout>
					</Frame>
				</ViewCell>
			</DataTemplate>
		</ListView.ItemTemplate>
	</ListView>

MainPage.cs:

private async void OnListViewItemSelected(object sender, SelectedItemChangedEventArgs args)
        {
            (sender as ListView).SelectedItem = null;

            if (args.SelectedItem != null)
            {
                PageDataViewModel pageData = args.SelectedItem as PageDataViewModel;
                Page page = (Page)Activator.CreateInstance(pageData.Type);
                await Navigation.PushAsync(page);
            }
        }

PageDataViewModel.cs

public class PageDataViewModel
    {
        public PageDataViewModel(Type type, string title, string description)
        {
            Type = type;
            Title = title;
            Description = description;
        }

        public Type Type { private set; get; }

        public string Title { private set; get; }

        public string Description { private set; get; }

        static PageDataViewModel()
        {
            All = new List<PageDataViewModel>
            {
                new PageDataViewModel(typeof(VerticalListPage), "Vertical List",
                                      "DataTemplate"),
            };
        }

        public static IList<PageDataViewModel> All { private set; get; }
    }

Relevant log output

No response

@mthanson8333 mthanson8333 added the t/bug Something isn't working label Oct 1, 2024
@drasticactions drasticactions changed the title NavigateCommand Not Working [WinUI] Command on TableView only invokes once. Oct 2, 2024
@drasticactions
Copy link
Contributor

I can reproduce this.

https://github.com/dotnet/maui-samples/blob/main/8.0/UserInterface/Views/CollectionViewDemos/CollectionViewDemos/Views/MainPage.xaml#L6-L213

That menu is a TableView, and apparently once you invoke one event, you can't invoke another one, even if it's a different command. I don't think the issue you linked is related to this though: The construction of that view is different.

@mthanson8333
Copy link
Author

Closing issue since question is asked at #21112

@umeshkamble
Copy link

@mthanson8333
I have tried below code its works.
Return to menu and click on other menu items. Its working
<TableView x:Name="tableList" Intent="Menu"> <TableRoot> <TableSection Title="Layout"> <TextCell Command="{Binding Path=BindingContext.NavigateCommand, Source={x:Reference tableList}}" CommandParameter="{x:Type views:VerticalListTextPage}" Detail="Text" Text="Vertical list" /> </TableSection> </TableRoot> </TableView>

@mthanson8333
Copy link
Author

Thanks for your help. I closed the issue since ticket #21112 is already addressing issue.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-listview ListView and TableView platform/windows 🪟 t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants