Bug 60654 - NavigationPage via x:Arguments XAML: runtime error
Summary: NavigationPage via x:Arguments XAML: runtime error
Status: CONFIRMED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.5.0
Hardware: PC Windows
: Normal major
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-11-13 20:30 UTC by Adam Patridge [MSFT]
Modified: 2017-11-14 00:20 UTC (History)
3 users (show)

Tags: navigationpage, x:Arguments, xaml, ac
Is this bug a regression?: ---
Last known good build:


Attachments
Reproduction solution (following listed steps) (1.50 MB, application/x-zip-compressed)
2017-11-13 20:30 UTC, Adam Patridge [MSFT]
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 60654 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description Adam Patridge [MSFT] 2017-11-13 20:30:59 UTC
Created attachment 25676 [details]
Reproduction solution (following listed steps)

While it may not be the ideal way to construct a NavigationPage, trying to create it entirely in XAML with x:Arguments parameters for the root page will throw an exception at runtime (confirmed on iOS, Android, and UWP).

## Steps

1. File > New Forms cross-platform app
2. Change generated MainPage.xaml.cs class to a NavigationPage
3. Change MainPage.xaml XAML to something like this

<NavigationPage xmlns="http://xamarin.com/schemas/2014/forms"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            xmlns:local="clr-namespace:Clock"
            x:Class="SomeProject.MainPage">
    <x:Arguments>
        <ContentPage>
            <ScrollView>
                <StackLayout>
                    <Button Text="Click me" />
                </StackLayout>
            </ScrollView>
        </ContentPage>
    </x:Arguments>
</NavigationPage>

4. Run app on iOS, Android, or UWP

This also applies when a page is a separate XAML file and is included as the value(s) in the `x:Arguments` content.

## Expected

App would load with a navigation page starting with the single-button root page.

## Actual

Exception thrown.

> [on iOS] System.InvalidOperationException: NavigationPage must have a root Page before being used. Either call PushAsync with a valid Page, or pass a Page to the constructor before usage.

## System info

Microsoft Visual Studio Enterprise 2017 
Version 15.4.3
VisualStudio.15.Release/15.4.3+27004.2008
Microsoft .NET Framework
Version 4.7.02556

Installed Version: Enterprise

Architecture Diagrams and Analysis Tools   00369-60000-00001-AA352
Microsoft Architecture Diagrams and Analysis Tools

Visual Basic 2017   00369-60000-00001-AA352
Microsoft Visual Basic 2017

Visual C# 2017   00369-60000-00001-AA352
Microsoft Visual C# 2017

Visual F# 4.1   00369-60000-00001-AA352
Microsoft Visual F# 4.1

…

Xamarin   4.7.10.38 (34c1b6c)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android SDK   8.0.2.1 (HEAD/c2a33d8ea)
Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK   11.3.0.47 (51128b8)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.