maui
maui copied to clipboard
[Mac Catalyst] DeviceDisplay.MainDisplayInfoChanged event not getting raised
Description
The DeviceDisplay.MainDisplayInfoChanged event is not getting raised when the main display information changes on macOS. For example, when changing display options (in Settings > Displays) like resolution, scaling, rotation, etc., or when switching the display that is designated as the Main display.
By way of comparison, the same event does get raised when changes are made on Windows. In multi-display setups, the event will also get raised on Windows when moving an application Window from one display to another.
Overarching expectation is that the behavior is consistent between Windows and Mac Catalyst where platform SDKs support detection of changes to those display screen metrics represented in the DisplayInfo
Steps to Reproduce
Subscribe the DeviceDisplay.MainDisplayInfoChanged event in the MainPage.xaml.cs
class of a file -> new .NET MAUI app outputting the serialized DeviceInfo provided by the DisplayInfoChangedEventArgs.
readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
{
WriteIndented = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
};
public MainPage()
{
InitializeComponent();
DeviceDisplay.Current.MainDisplayInfoChanged += OnMainDisplayInfoChanged;
}
void OnMainDisplayInfoChanged(object sender, DisplayInfoChangedEventArgs e)
{
var updateTextBuilder = new StringBuilder();
updateTextBuilder.AppendLine($"Raised {nameof(OnMainDisplayInfoChanged)} : {DateTimeOffset.Now.ToLocalTime()}");
updateTextBuilder.AppendLine($"");
updateTextBuilder.Append(JsonSerializer.Serialize(e.DisplayInfo, _serializerOptions));
System.Diagnostics.Debug.WriteLine(updateTextBuilder.ToString());
}
Using screen resolution as the example of a change to display information expected to raise the event.
- Run the .NET MAUI app on macOS
- Open the Settings app and change the screen resolution for the designated Main display
EXPECTED
The DeviceDisplay.MainDisplayInfoChanged event gets raised
ACTUAL
The event does not get raised
Link to public reproduction project repository
No response
Version with bug
8.0.40 SR5
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
macOS
Affected platform versions
Mac Catalyst 13.1
Did you find any workaround?
No response
Relevant log output
No response