Skip to content

WinUI: TabbedPage pages provided by a DataTemplate crash when swapping to a different tab. #14572

@Keflon

Description

@Keflon

Description

When a TabbedPage is used as the root application page and the child pages are provided using ItemsSource, the app crashes when a tab other than the current tab is pressed.
image

Steps to Reproduce

  1. Create a new MAUI app.
  2. Replace App.xaml.cs with this:
public partial class App : Application
{
    public App()
    {
        InitializeComponent();

        var rootPage = new TabbedPage();
        rootPage.ItemsSource = new List<object> { new Vm1(), new Vm2(), new Vm3() };
        rootPage.ItemTemplate = new TabbedItemTemplateSelector();
        MainPage = rootPage;
    }
    public class Vm1 { }
    public class Vm2 { }
    public class Vm3 { }
    class TabbedItemTemplateSelector : DataTemplateSelector
    {
        protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
        {
            if (item is Vm1)
                return new DataTemplate(() => new ContentPage() { Title = "Type 1" });
            if (item is Vm2)
                return new DataTemplate(() => new ContentPage() { Title = "Type 2" });
            if (item is Vm3)
                return new DataTemplate(() => new ContentPage() { Title = "Type 3" });

            return null;
        }
    }
}
  1. Run in on Windows and tap for a crash.

Link to public reproduction project repository

https://github.com/Keflon/TabbedPageTemplateBug

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

Latest

Did you find any workaround?

No. If anyone finds one please share here.

Relevant log output

Exception thrown: 'System.ArgumentException' in WinRT.Runtime.dll
WinRT information: The parameter is incorrect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-controls-tabbedpageTabbedPagearea-layoutStackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenterpartner/syncfusionIssues / PR's with Syncfusion collaborationplatform/windowss/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions