0

I created cross platform project for android having dependencies xamarin.essentials\1.5.3.2 and xamarin.forms\4.8.0.1451 (the defaults) with tabbed layout. Then I added TestMasterDetailPage using MasterDetailPage template. AppShell.xaml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<Shell xmlns="http://xamarin.com/schemas/2014/forms" 
       xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
       xmlns:local="clr-namespace:MasterDetailTest.Views"
       Title="MasterDetailTest"
       x:Class="MasterDetailTest.AppShell">
    <TabBar>
        <ShellContent Title="About" Icon="icon_about.png" Route="AboutPage" ContentTemplate="{DataTemplate local:AboutPage}" />
        <ShellContent Title="Browse" Icon="icon_feed.png" ContentTemplate="{DataTemplate local:ItemsPage}" />
        <ShellContent Title="TestMasterDetailPage" Route="TestMasterDetailPage" ContentTemplate="{DataTemplate local:TestMasterDetailPage}" />
    </TabBar>
</Shell>

I removed some unused code and added 3rd tab in TabBar. When launching it and pressing on new tab I get error in external code: System.InvalidCastException: 'Specified cast is not valid.'

I found this question which looks identical, however it's 2yo and I'm not sure if shell was used for template at that time. Also, like mentioned before, crash happens somewhere in external code.

user2820173
  • 308
  • 2
  • 13
  • you can't nest a MasterDetail inside of a Tab – Jason Jan 06 '21 at 19:43
  • The exception was caused by the type of your page, so what type is your TestMasterDetailPage? You can check the AboutPage, which is defined as ``` public partial class AboutPage : ContentPage``` (And in XF5.0, if you are keen to update, which was just released, MasterDetail is renamed.) – Shaw Jan 06 '21 at 20:05
  • @user2820173 From [Xamarin.Forms Shell](https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/tabs#single-page-application), you can see that the ShellContent object should be set to a ContentPage object, but MasterDetailPage is MasterDetailPage object, they are different type. – Cherry Bu - MSFT Jan 07 '21 at 03:00

0 Answers0