Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeviceDisplay.Current.MainDisplayInfo not working #12214

Closed
mouralabank opened this issue Dec 19, 2022 · 4 comments
Closed

DeviceDisplay.Current.MainDisplayInfo not working #12214

mouralabank opened this issue Dec 19, 2022 · 4 comments
Labels
platform/windows 🪟 s/needs-repro Attach a solution or code which reproduces the issue t/bug Something isn't working

Comments

@mouralabank
Copy link

Description

The displayInfo does not provide any information about the display on the App construction

image

If I add the same code on the event OnCounterClicked then it works.

image

Steps to Reproduce

Create a Maui Application and add the following in App.xaml.cs:

namespace TestWindow;

public partial class App : Application
{
	public App()
	{
		InitializeComponent();

		MainPage = new AppShell();
	}
    protected override Window CreateWindow(IActivationState activationState)
    {
        Window window = base.CreateWindow(activationState);

        // get screen size
        var disp = DeviceDisplay.Current.MainDisplayInfo;

        // get width and height
        var newWidth = disp.Width/2;
        var newHeight = disp.Height/2;

        // center the window
        window.X = (disp.Width / disp.Density - newWidth) / 2;
        window.Y = (disp.Height / disp.Density - newHeight) / 2;

        // resize
        window.Width = newWidth;
        window.Height = newHeight;
        return window;
    }
}

Link to public reproduction project repository

https://github.com/dotnet/maui/blob/main/.github/repro.md

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

windows10.0.19041.0

Did you find any workaround?

No

Relevant log output

No response

@mouralabank mouralabank added the t/bug Something isn't working label Dec 19, 2022
@jsuarezruiz jsuarezruiz added platform/windows 🪟 s/needs-repro Attach a solution or code which reproduces the issue labels Dec 19, 2022
@ghost
Copy link

ghost commented Dec 19, 2022

Hi @mouralabank. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@ghost ghost added the s/no-recent-activity Issue has had no recent activity label Dec 23, 2022
@ghost
Copy link

ghost commented Dec 23, 2022

This issue has been automatically marked as stale because it has been marked as requiring author feedback to reproduce the issue but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

@ghost ghost closed this as completed Dec 26, 2022
@tonydokun
Copy link

This ist a duplicate of #6976. @mouralabank the workaround is to use:

DeviceDisplay.MainDisplayInfoChanged += DeviceDisplay_MainDisplayInfoChanged;

and then use something like this:

 private void DeviceDisplay_MainDisplayInfoChanged(object? sender, DisplayInfoChangedEventArgs e)
    {
        MyMainDisplay = DeviceDisplay.Current.MainDisplayInfo;
        NotifyPropertyChanged(nameof(MyMainDisplay );
    }

@ghost
Copy link

ghost commented Jan 12, 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!

@ghost ghost removed the s/no-recent-activity Issue has had no recent activity label Jan 12, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Feb 11, 2023
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform/windows 🪟 s/needs-repro Attach a solution or code which reproduces the issue t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants