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.

exception upon use of OnPlatform WinUI

See original GitHub issue

Description

MAUI app crash when using OnPlatform WinUI. Here is the app xaml to reproduce the error. Please see the comment above the problem xaml code inside a Label tag

<?xml version="1.0" encoding="utf-8" ?>

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="SettingsCrash.SettingsPage"> <StackLayout BackgroundColor="Black" WidthRequest="480" VerticalOptions="Center" HorizontalOptions="Center" Padding="20">

    <Label Text="Settings" 
               FontSize="30"
               Margin="0,0,0,20"/>

    <StackLayout Orientation="Horizontal">
        <CheckBox IsChecked="True" />
        <Label Text="Function Log" Margin="{OnPlatform WinUI='-90,0,0,0'}" VerticalOptions="Center" InputTransparent="True"/>
    </StackLayout>
    <StackLayout Orientation="Horizontal">
        <CheckBox IsChecked="False" />
        <Label Text="Action Log" Margin="{OnPlatform WinUI='-90,0,0,0'}" VerticalOptions="Center" InputTransparent="True"/>
    </StackLayout>

    <StackLayout Orientation="Horizontal">
        <Label Text="Interval Log(Min)" VerticalOptions="Center" InputTransparent="True"/>
        <CheckBox IsChecked="True" />
        <Label Text="MaxMin Log(Min)" Margin="10,0,10,0" VerticalOptions="Center" InputTransparent="True"/>
    </StackLayout>

    <StackLayout Orientation="Horizontal">
        <Label Text="Pause updates on resize/move" Margin="0,0,20,0" VerticalOptions="Center" InputTransparent="True"/>
    </StackLayout>

    <StackLayout Orientation="Vertical" Margin="0,10,0,0">
        <Label Text="LogPath" />
        <Entry Text="ttt"
               IsReadOnly="True"/>
    </StackLayout>


    <Grid WidthRequest="440" 
              RowDefinitions="100" 
              ColumnDefinitions="*,*">
        <Button Text="Cancel"
                    Grid.Column="0"
                    HeightRequest="50"
                    WidthRequest="100"
                    />
        <Button Text="Save"
                    Grid.Column="1"
                    HeightRequest="50"
                    WidthRequest="100"

/> </Grid>

</StackLayout>
</ContentPage>

Steps to Reproduce

  1. create a new MAUI shell app
  2. in the AppShell.xaml, paste in this code:
<?xml version="1.0" encoding="UTF-8" ?>

<Shell x:Class="SettingsCrash.AppShell" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:SettingsCrash" Shell.FlyoutBehavior="Flyout">

<ShellContent
    Title="Home"
    ContentTemplate="{DataTemplate local:MainPage}"
    Route="MainPage" />

<ShellContent 
    Title="Settings" 
    ContentTemplate="{DataTemplate local:SettingsPage}"
    Route="SettingsPage"/>

<ShellContent 
    Title="Test here" />
</Shell>
  1. create another xaml file named SettingsPage.xaml and paste in this code: 4.<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="SettingsCrash.SettingsPage"> <StackLayout BackgroundColor="Black" WidthRequest="480" VerticalOptions="Center" HorizontalOptions="Center" Padding="20">

     <Label Text="Settings" 
                FontSize="30"
                Margin="0,0,0,20"/>
    
     <StackLayout Orientation="Horizontal">
         <CheckBox IsChecked="True" />
         <Label Text="Function Log" Margin="{OnPlatform WinUI='-90,0,0,0'}" VerticalOptions="Center" InputTransparent="True"/>
     </StackLayout>
     <StackLayout Orientation="Horizontal">
         <CheckBox IsChecked="False" />
    
        <Label Text="Action Log" Margin="{OnPlatform WinUI='-90,0,0,0'}" VerticalOptions="Center" InputTransparent="True"/>
    </StackLayout>

    <StackLayout Orientation="Horizontal">
        <Label Text="Interval Log(Min)" VerticalOptions="Center" InputTransparent="True"/>
        <CheckBox IsChecked="True" />
        <Label Text="MaxMin Log(Min)" Margin="10,0,10,0" VerticalOptions="Center" InputTransparent="True"/>
    </StackLayout>

    <StackLayout Orientation="Horizontal">
        <Label Text="Pause updates on resize/move" Margin="0,0,20,0" VerticalOptions="Center" InputTransparent="True"/>
    </StackLayout>

    <StackLayout Orientation="Vertical" Margin="0,10,0,0">
        <Label Text="LogPath" />
        <Entry Text="ttt"
               IsReadOnly="True"/>
    </StackLayout>


    <Grid WidthRequest="440" 
              RowDefinitions="100" 
              ColumnDefinitions="*,*">
        <Button Text="Cancel"
                    Grid.Column="0"
                    HeightRequest="50"
                    WidthRequest="100"
                    />
        <Button Text="Save"
                    Grid.Column="1"
                    HeightRequest="50"
                    WidthRequest="100"

/> </Grid>

</StackLayout>
</ContentPage>

build the app, at runtime, select the Settings menu item from the flyout menu.

Version with bug

6.0.400

Last version that worked well

6.0 Release Candidate 3

Affected platforms

Windows, I was not able test on other platforms

Affected platform versions

Windows Build 22000.856

Did you find any workaround?

workaround is to remove the use of Margin=“{OnPlatform}”

Relevant log output

no specific log output

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
linkaiyucommented, Aug 30, 2022

This issue can only be reproduced in a custom application. The owner of the app is on vacation. Once he is back, we will give you access to the repo

0reactions
msftbot[bot]commented, May 15, 2023

Hello lovely human, thank you for your comment on this issue. Because this issue has been closed for a period of time, please strongly consider opening a new issue linking to this issue instead to ensure better visibility of your comment. Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid cast when tryng to set Grid dimensions data in XAML
Message: Unable to cast object of type 'Xamarin.Forms.OnPlatform`1[System.Int16]' to type 'Xamarin.Forms.GridLength'. Type: System.
Read more >
Application.UnhandledException Event (Windows.UI.Xaml)
Occurs when an exception can be handled by app code, as forwarded from a native-level Windows Runtime error. Apps can mark the occurrence...
Read more >
Building a XAML UserControl for WinUI, UWP, WPF or ...
One of the powerful aspects of any XAML platform is the ability to define your own controls. In this post we're going to...
Read more >
Getting started with Microsoft .NET MAUI
NET MAUI over other cross-platform frameworks? Some frameworks, such as React Native, are not a fully cross platform app framework. To use ......
Read more >
Questions on UI for Xamarin Forum
Hello Support,. We are using RadListView and RadDataGrid controls in our UWP and iOS applications. On these controls we observed there is a...
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