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.

Width and Height value of ContentPage not filled

See original GitHub issue

Description

The Width and Height property of the ContentPage do not update. They remain -1 and -1.

P. S.: I don’t know which MAUI version I am using. I have the VS2022 version 17.2.0 Preview installed.

Steps to Reproduce

  1. Add the following code to the MainPage.xaml:
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MauiApp2.MainPage"
             BackgroundColor="{DynamicResource SecondaryColor}"
             x:Name="cp">

    <Grid x:Name="grid">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="100"/>
        </Grid.RowDefinitions>
        <Label Grid.Row="1" x:Name="label1"></Label>
        <Label Grid.Row="2" x:Name="label2"></Label>
        <Button Grid.Row="3" Text="Refresh" Clicked="RefreshNumbers"></Button>
    </Grid>
</ContentPage>
  1. Add the following code to the Mainpage.xaml.cs
namespace MauiApp2;

public partial class MainPage : ContentPage
{
	public MainPage()
	{
		InitializeComponent();
	}

	public void RefreshNumbers(object sender, EventArgs args)
    {
		label1.Text = "The size of the ContentPage is:\nWidth:" + cp.Width + " Height: " + cp.Height;
		label2.Text = "The size of the Grid is:\nWidth:" + grid.Width + " Height: " + grid.Height;
	}
}
  1. Compile and press the button. The values of the Grid layout will update, but the ContentPage will show -1 and -1.

Version with bug

Unknown/Other (please specify)

Last version that worked well

Unknown/Other

Affected platforms

Android, Windows

Affected platform versions

Windows 10 (OS build 19044.1526), Android 11

Did you find any workaround?

No

Relevant log output

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
PureWeencommented, Feb 27, 2022

This should be fixed in the next preview release

image
0reactions
Tardigrade42commented, Apr 29, 2022

This looks just as I expected! Thank you 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Width of contentview change of size, even when a value is ...
A column given the width * will take the space that is available. ... width to 30% ( .3 ). The height of...
Read more >
VerticalStackLayout - .NET MAUI
In a VerticalStackLayout, child views expand to fill the available width when their size isn't explicitly set.
Read more >
App crash ContentPage with RadAutoComplete
Setting the width to RadAutoComplete did the trick. now it works perfectly. WidthRequest="100". But setting it like this throws same error,.
Read more >
Xamarin Forms LayoutOption Differences
Fill – expands to all the available space inside the parent view. AndExpand – tells the View to expand to the full width...
Read more >
Item Size Customization in Xamarin ListView (SfListView)
ItemType: Identifies the item type of the queried item. Handled: Decides whether the specified size can be set to the item or not....
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