I have a .NET MAUI application that was working for fine for android when the orientation changes from portrait to landscape. However, after some packages for the project were upgraded, I now have a weird black void on the left side of the screen when the orientation has been changed to landscape. As if the whole screen shifted by a few pixels to the right. (Note: I am referring to the whole PAGE object itself, not any XAML element in the layout.) I do wonder if this problem can be solved without the need to revert the packages though.
NOTE: I asked the same question on SO, but they were not much help. Here is a link to the image of the problem that I posted:
Image Here[
^]
What I have tried:
I tried removing some code that I thought would be the culprit at the top of certain XAML pages in the ContentPage.Behaviors tags:
<ContentPage.Behaviors> <toolkit:StatusBarBehavior StatusBarColor="#4085c0" StatusBarStyle="LightStyle" /> </ContentPage.Behaviors>
However, that did not work. (It was a shot in the dark anyway.) I also double-checked the android code for my orientation service as seen below:
public enum DeviceOrientation
{
Undefined,
Landscape,
Portrait
}
public class DeviceOrientationService : IDeviceOrientationService
{
#if IOS
#elif ANDROID
public DeviceOrientation GetOrientation()
{
var getDeviceCurrentActivity = ActivityStateManager.Default.GetCurrentActivity();
var orientation = getDeviceCurrentActivity.RequestedOrientation;
if (orientation == Android.Content.PM.ScreenOrientation.Landscape)
{
return DeviceOrientation.Landscape;
}
return DeviceOrientation.Portrait;
}
#endif
public void SetOrientation(DeviceOrientation orientation)
{
#if ANDROID
var getDeviceCurrentActivity = ActivityStateManager.Default.GetCurrentActivity();
if (orientation == DeviceOrientation.Landscape)
{
getDeviceCurrentActivity.RequestedOrientation = Android.Content.PM.ScreenOrientation.Landscape;
}
else
{
getDeviceCurrentActivity.RequestedOrientation = Android.Content.PM.ScreenOrientation.Portrait;
}
#elif IOS
#endif
}
}
}
I also have tried reverting the MAUI Controller packages back to 18.0.14 from 18.0.21 since I noticed that this started happening after that revert, but still nothing happened which is strange. I will continue to look through the packages to find the culprit, but I'm just wondering if anyone has an idea of another way to fix this as mentioned earlier. I thought for sure that it was this package that needed to be reverted. But I guess not. Maybe I missed something. If I did I will update this question with an answer. But at any rate if anyone has an idea of another way to fix this, that would be great. Also, more importantly, if anyone has any suggestions where to continue to look for a possible answer in either the code config files, or what have you. I honestly have no clue. I don't think it matter s to know, but I am also using the navigation objects from the Prism MAUI library, though I don't think this is a prism issue.
Here are my layout pages. They are relatively the same other than a text field on the first one
Here is the first one:
<pre>="1.0"="utf-8"
<ContentPage
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:control="clr-namespace:MyApp.Controls"
xmlns:datacollection="clr-namespace:MyApp.DataCollection"
xmlns:views="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
x:DataType="datacollection:SigningViewModel"
x:Name="Form"
Padding="0"
x:Class="MyApp.SigningPage1"
Title="{Binding Person, Converter={StaticResource PersonNameConverter}}"
NavigationPage.HasBackButton="False"
>
<ContentPage.Behaviors>
<views:StatusBarBehavior StatusBarColor="#4085c0" StatusBarStyle="LightContent" />
</ContentPage.Behaviors>
<ContentPage.Content>
<Grid>
<StackLayout IsVisible="{Binding Busy, Converter={StaticResource not}}">
<Grid ColumnDefinitions="*,*">
<Grid ColumnDefinitions="*,*" Grid.Column="1">
<Button Text="Clear" Grid.Column="1" HorizontalOptions="End" Command="{Binding ClearSignatureCommand}" BackgroundColor="White" TextColor="DarkRed"/>
</Grid>
</Grid>
<views:DrawingView x:Name="signatureView"
Lines="{Binding SignatureLines}"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
BackgroundColor="White"
LineColor="Black"
LineWidth="2"
DrawingLineCompletedCommand="{Binding LineCompletedCommand}"
IsMultiLineModeEnabled="true"
ShouldClearOnFinish="false" />
<Label Text="Please sign" Style="{StaticResource error}" IsVisible="{Binding DisplayNotSignedError }" />
<Entry Text="{Binding OtherSignature}" Placeholder="Enter Name"/>
<Label x:Name="OtherSignatureNotEntered" Text="Please enter the name of the person signing" Style="{StaticResource error}" IsVisible="{Binding DisplaySignatureError }" />
<Grid HorizontalOptions="FillAndExpand" MinimumHeightRequest="25">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Text="Cancel" Command="{Binding CancelCommand}" HorizontalOptions="FillAndExpand" Style="{StaticResource default}" />
<Button Grid.Column="1" Text="Submit" Command="{Binding SubmitCommand}" HorizontalOptions="FillAndExpand" Style="{StaticResource primary}" />
</Grid>
</StackLayout>
<control:BusyOverlay IsVisible="{Binding Busy}"
BackgroundColor="White"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand"
/>
</Grid>
</ContentPage.Content>
</ContentPage>
Here is the second one:
="1.0"="utf-8"
<ContentPage
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:control="clr-namespace:MyApp.Controls"
xmlns:datacollection="clr-namespace:MyApp.DataCollection"
xmlns:views="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
x:DataType="datacollection:SigningViewModel2"
x:Name="Form"
Padding="0"
x:Class="MyApp.SigningPage2"
Title="{Binding Person, Converter={StaticResource PersonConverter}}"
>
<ContentPage.Behaviors>
<views:StatusBarBehavior StatusBarColor="#4085c0" StatusBarStyle="LightContent" />
</ContentPage.Behaviors>
<ContentPage.Content>
<Grid>
<StackLayout IsVisible="{Binding Busy, Converter={StaticResource not}}">
<Grid ColumnDefinitions="*,*">
<Button Text="Clear" Grid.Column="1" HorizontalOptions="End" WidthRequest="90" Command="{Binding ClearSignatureCommand}" BackgroundColor="White" TextColor="DarkRed"/>
</Grid>
<views:DrawingView x:Name="signatureView"
Lines="{Binding SignatureLines}"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
BackgroundColor="White"
LineColor="Black"
LineWidth="2"
DrawingLineCompletedCommand="{Binding LineCompletedCommand}"
IsMultiLineModeEnabled="true"
ShouldClearOnFinish="false" />
<Label Text="Please sign" Style="{StaticResource error}" IsVisible="{Binding DisplayNotSignedError }" />
<Grid HorizontalOptions="FillAndExpand" MinimumHeightRequest="25">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Text="Cancel" Command="{Binding CancelCommand}" HorizontalOptions="FillAndExpand" Style="{StaticResource default}" />
<Button Grid.Column="1" Text="Submit" Command="{Binding SubmitCommand}" HorizontalOptions="FillAndExpand" Style="{StaticResource primary}" />
</Grid>
</StackLayout>
<control:BusyOverlay IsVisible="{Binding Busy}"
BackgroundColor="White"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand"/>
</Grid>
</ContentPage.Content>
</ContentPage>