I have a .NET MAUI app that I am trying to build out, and I want it to exhibit some behaviours when the orientation changes.
I have added this to the Code Behind of the Content Page, however putting a breakpoint in the Current_MainDisplayInfoChanged
method never gets reached.
I can’t work out why?
public partial class Scoreboard : ContentPage
{
public ScoreboardViewModel VM;
public Scoreboard(ScoreboardViewModel vm)
{
InitializeComponent();
VM = vm;
BindingContext = vm;
DeviceDisplay.Current.MainDisplayInfoChanged += Current_MainDisplayInfoChanged;
}
private void Current_MainDisplayInfoChanged(object? sender, DisplayInfoChangedEventArgs e)
{
if (e.DisplayInfo.Orientation == DisplayOrientation.Landscape)
{
this.VM.ViewLandscape = true;
this.VM.ViewPortrait = false;
}
else if (e.DisplayInfo.Orientation == DisplayOrientation.Portrait)
{
this.VM.ViewLandscape = false;
this.VM.ViewPortrait = true;
}
else
{
this.VM.ViewLandscape = false;
this.VM.ViewPortrait = true;
}
}
}