Hello,
You can try to create a task that can be done after a delay and then call MainDisplayInfo
, but it doesn't work if you want to get MainDisplayInfo
early in the application life cycle.
protected override void OnAppearing()// works on App() constructor , App OnStart(), MainPage() constructor
{
base.OnAppearing();
MainThread.BeginInvokeOnMainThread(async () => await DelayedShowWidth());
}
private async Task DelayedShowWidth()
{
await Task.Delay(500);
var mainDisplayInfo = DeviceDisplay.MainDisplayInfo;
// do something
}
There is an issue discussing MainDisplayInfo
in AppShell
constructor on GitHub: https://github.com/dotnet/maui/issues/6976, you could refer to this workaround :https://github.com/dotnet/maui/issues/6976#issuecomment-1122175778 and follow the progress.
Best Regards,
Wenyan Zhang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.