WinUI: TabbedPage pages provided by a DataTemplate crash when swapping to a different tab.
See original GitHub issueDescription
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.
Steps to Reproduce
- Create a new MAUI app.
- 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;
}
}
}
- 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:
- Created 5 months ago
- Comments:7 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Stacktrace:
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.