question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 5 months ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
jsuarezruizcommented, Apr 14, 2023

Stacktrace:

   at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|20_0(Int32 hr)
   at ABI.Microsoft.UI.Xaml.IFrameworkElementOverridesMethods.MeasureOverride(IObjectReference _obj, Size availableSize)
   at Microsoft.UI.Xaml.FrameworkElement.MeasureOverride(Size availableSize)
   at Microsoft.UI.Xaml.FrameworkElement.Microsoft.UI.Xaml.IFrameworkElementOverrides.MeasureOverride(Size availableSize)
   at ABI.Microsoft.UI.Xaml.IFrameworkElementOverrides.Do_Abi_MeasureOverride_0(IntPtr thisPtr, Size availableSize, Size* result)
1reaction
zerihalcommented, Apr 19, 2023

Could not get past this issue with using datatemplate and above workaround is not suitable for my purposes.

Alternate workaround, which did seem to work OK on all platforms was to get rid of the datatemplate all together and just dynamically add the contents of of what was previously ItemsSource to the TabbedPage children in the constructor (retaining the same view model). Not an ideal solution I know, but works for now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MAUI Tabbed Page crashes when it is called from another ...
As an alternative workaround, you may be able to set the App.MainPage to a TabbedPage to get it resolved. Share.
Read more >
Xamarin.Forms 5.0.0.2612 (5.0.0 Service Release 15) ...
Release notes detailing new features, improvements, and issues fixed in Xamarin.Forms 5.0.0.2612 (5.0.0 Service Release 15)
Read more >
Hello i have an issue with xct:TouchEffect on release mode ...
A tabbed page contains child page objects; one for each tab. ... Other page types are available, and are mostly used for enabling...
Read more >
Dave's Tech Blog - RSSing.com
The OnPlatform markup extension is used to specify the different resource filenames on iOS and Android. On iOS, the custom renderer ensures that ......
Read more >
How to solve Xamarin.Forms.Platform.Android ...
I was too facing this with ListView in TabbedPage so while changing tabs I was resetting ItemSource of Listview , solved my issue...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found