You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since a default implementation using xaml + code behind has a call to InitializeComponent() in it's constructor I believe maybe we should simply let the code behind file call it?
Original description
I used the default Caliburn.Micro sample with Xamarin.Forms and modified my HomeView.xaml file to use a tabbed page:
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPagexmlns="http://xamarin.com/schemas/2014/forms"xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"x:Class="Setup.Forms.Views.HomeView">
<ContentPageTitle="First tab">
<LabelText="Testing first tab">
</Label></ContentPage>
<ContentPageTitle="Second tab">
<LabelText="Testing second tab"></Label>
</ContentPage>
</TabbedPage>
The view will show up but now the tabs have been added multiple times (4 times instead of 2). I've located the error to something happening inside the ViewLocator.LocateForModel(viewModel, null, null); code. If I do a new HomeView() the problem will not appear.
Note:
I've also seen this when using the NavigationService. In this case a toolbar button was added multiple times. I am guessing it also uses ViewLocator.LocateForModel internally? It's like all Xaml gets evaluated twice or something.
Here's a picture of the result:
The text was updated successfully, but these errors were encountered:
Thanks for this, I'll have to look into the generated code by Xamarin.Forms. The other xaml platforms have guards in to detect duplicate initialization, it appears XF doesn't.
This is here to support xaml files without a code behind which admittedly isn't a highly used feature.
This was a feature to support xaml files with no code behind that
doesn't get much use. It worked well because the WIndows generated code
guards against double initialisation, Xamarin.Forms doesn't.
Update: Might have found the bug
It seems
InitializeComponent();
gets called twice forViewLocator.LocateForModel
because of the following code:Since a default implementation using xaml + code behind has a call to
InitializeComponent()
in it's constructor I believe maybe we should simply let the code behind file call it?Original description
I used the default Caliburn.Micro sample with Xamarin.Forms and modified my
HomeView.xaml
file to use a tabbed page:The view will show up but now the tabs have been added multiple times (4 times instead of 2). I've located the error to something happening inside the
ViewLocator.LocateForModel(viewModel, null, null);
code. If I do anew HomeView()
the problem will not appear.Note:
I've also seen this when using the
NavigationService
. In this case a toolbar button was added multiple times. I am guessing it also usesViewLocator.LocateForModel
internally? It's like all Xaml gets evaluated twice or something.Here's a picture of the result:
The text was updated successfully, but these errors were encountered: