dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.98k stars 1.71k forks source link

Grid layout breaks in build target='Release' when ColumnDefinitions defined via StaticResource #20244

Open MattHoppler opened 7 months ago

MattHoppler commented 7 months ago

Description

When the ColumnDefinitions of a grid layout is defined as a static ressource the layout breaks on target='Release'

Correct Layout on build target 'Debug'

Grid_correct

Broken layout on build Traget 'Release'

Grid_broken

Code

    <ContentPage.Resources >
        <System:String x:Key="GridColDef">*, *, *, *, *, auto</System:String>    
    </ContentPage.Resources> 

    <ScrollView>
        <Grid ColumnDefinitions="50,200,*" RowDefinitions="{StaticResource GridColDef}">
            <Image Grid.Column="0" Source="dotnet_bot.png" HeightRequest="50" Aspect="AspectFit" VerticalOptions="Center"/>
            <Label Grid.Column="1" Text="My Label 1" Style="{StaticResource Headline}" VerticalOptions="Center"/>
            <Entry Grid.Column="2" Text="My Entry 1" VerticalOptions="Center"/>

            <Image Grid.Row="1" Grid.Column="0" Source="dotnet_bot.png" HeightRequest="50" Aspect="AspectFit" VerticalOptions="Center"/>
            <Label Grid.Row="1" Grid.Column="1" Text="My Label 2" Style="{StaticResource Headline}" VerticalOptions="Center"/>
            <Entry Grid.Row="1" Grid.Column="2" Text="My Entry 2" />

            <Image Grid.Row="2" Grid.Column="0" Source="dotnet_bot.png" HeightRequest="50" Aspect="AspectFit" VerticalOptions="Center"/>
            <Label Grid.Row="2" Grid.Column="1" Text="My Label 3" Style="{StaticResource Headline}" VerticalOptions="Center"/>
            <Entry Grid.Row="2" Grid.Column="2" Text="My Entry 3" VerticalOptions="Center"/>

            <Image Grid.Row="3" Grid.Column="0" Source="dotnet_bot.png" HeightRequest="50" Aspect="AspectFit" VerticalOptions="Center"/>
            <Label Grid.Row="3" Grid.Column="1" Text="My Label 4" Style="{StaticResource Headline}" VerticalOptions="Center"/>
            <Entry Grid.Row="3" Grid.Column="2" Text="My Entry 4" VerticalOptions="Center"/>

            <Image Grid.Row="4" Grid.Column="0" Source="dotnet_bot.png" HeightRequest="50" Aspect="AspectFit" VerticalOptions="Center"/>
            <Label Grid.Row="4" Grid.Column="1" Text="My Label 5" Style="{StaticResource Headline}" VerticalOptions="Center"/>
            <Entry Grid.Row="4" Grid.Column="2" Text="My Entry 5" VerticalOptions="Center"/>

            <Button Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="3" x:Name="CounterBtn" Text="Click me" WidthRequest="150"  HorizontalOptions="Fill" />
        </Grid>
    </ScrollView>

Steps to Reproduce

  1. Create a .net Maui Project
  2. Replace content in MainPage with sample above
  3. Build app in target Release
  4. Start App -> Layout is broken

Link to public reproduction project repository

No response

Version with bug

8.0.3

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android, Windows

Affected platform versions

No response

Did you find any workaround?

Never define ColumnDefinitions via StaticResource

Relevant log output

No response

MattHoppler commented 7 months ago

Sample project is here https://github.com/MattHoppler/GridLayoutColDefStatic/tree/62184bf8c191852d4301e641805ad86cbef597dd

ghost commented 7 months ago

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

StephaneDelcroix commented 6 months ago

confirmed. there's an issue with XamlC

StephaneDelcroix commented 6 months ago

one fix would be to have the resource of type RowDefinitionsCollection (with x:Shared="false")