-
Notifications
You must be signed in to change notification settings - Fork 410
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix display position and size of Popup (#1320)
* Fix display position and size of Popup * Consider the height of the status bar and navigation bar * Update Formatting, Change `NullReferenceException` -> `InvalidOperationException`, Add message to `InvalidOperationException` * Changed how to get the height of Navigation Bar and Status Bar * Fix conflict * Add PopupLayoutPage * Rename `PopupLayout` -> `PopupLayoutAlignment` * Update Formatting * Throw exception for unsupported switch case * Remove `UIEdgeInserts` --------- Co-authored-by: Brandon Minnick <[email protected]>
- Loading branch information
Showing
11 changed files
with
415 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
213 changes: 213 additions & 0 deletions
213
samples/CommunityToolkit.Maui.Sample/Pages/Views/Popup/PopupLayoutAlignmentPage.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,213 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<pages:BasePage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="CommunityToolkit.Maui.Sample.Pages.Views.PopupLayoutAlignmentPage" | ||
xmlns:pages="clr-namespace:CommunityToolkit.Maui.Sample.Pages" | ||
xmlns:viewModels="clr-namespace:CommunityToolkit.Maui.Sample.ViewModels.Views" | ||
x:TypeArguments="viewModels:PopupLayoutAlignmentViewModel" | ||
x:DataType="viewModels:PopupLayoutAlignmentViewModel" | ||
Title="Popup Layout Alignment"> | ||
|
||
<Grid RowDefinitions="64,44,32,44,24,44,*" | ||
ColumnDefinitions="*,*,*,*,*,*,*,*" | ||
ColumnSpacing="5"> | ||
<Label Grid.Row="0" | ||
Grid.ColumnSpan="8" | ||
HorizontalTextAlignment="Center" | ||
Text="Popup allows you to position it on the page using its LayoutAlignmentOptions, HorizontalOptions and VerticalOptions" /> | ||
|
||
<Label Grid.Row="1" | ||
Grid.Column="0" | ||
FontSize="12" | ||
Text="Width" | ||
FontAttributes="Bold" | ||
VerticalOptions="Center"/> | ||
|
||
<Entry Grid.Row="1" | ||
Grid.Column="1" | ||
Grid.ColumnSpan="2" | ||
Text="100" | ||
x:Name="widthEntry" | ||
Keyboard="Numeric" | ||
WidthRequest="100" | ||
HorizontalTextAlignment="End" /> | ||
|
||
<Label Grid.Row="1" | ||
Grid.Column="4" | ||
FontSize="12" | ||
Text="Height" | ||
FontAttributes="Bold" | ||
VerticalOptions="Center" /> | ||
|
||
<Entry Grid.Row="1" | ||
Grid.Column="5" | ||
Grid.ColumnSpan="2" | ||
Text="100" | ||
x:Name="heightEntry" | ||
Keyboard="Numeric" | ||
WidthRequest="100" | ||
HorizontalTextAlignment="End" /> | ||
|
||
<Label | ||
Grid.Row="2" | ||
Grid.Column="0" | ||
Grid.ColumnSpan="8" | ||
Text="HorizontalOptions" | ||
VerticalOptions="End" | ||
FontAttributes="Bold" /> | ||
|
||
<Label | ||
Grid.Row="3" | ||
Grid.Column="0" | ||
FontSize="13" | ||
Text="Start" | ||
VerticalOptions="Center" | ||
HorizontalOptions="End"/> | ||
|
||
<RadioButton | ||
Grid.Row="3" | ||
Grid.Column="1" | ||
x:Name="HorizontalOptionsStartRadioButton" | ||
IsChecked="True" | ||
HorizontalOptions="Start" | ||
VerticalOptions="Center" | ||
GroupName="HorizontalLayoutOptions" /> | ||
|
||
<Label | ||
Grid.Row="3" | ||
FontSize="13" | ||
Grid.Column="2" | ||
Text="Center" | ||
VerticalOptions="Center" /> | ||
|
||
<RadioButton | ||
Grid.Row="3" | ||
Grid.Column="3" | ||
x:Name="HorizontalOptionsCenterRadioButton" | ||
IsChecked="False" | ||
HorizontalOptions="Start" | ||
VerticalOptions="Center" | ||
GroupName="HorizontalLayoutOptions" /> | ||
|
||
<Label | ||
Grid.Row="3" | ||
Grid.Column="4" | ||
FontSize="13" | ||
Text="End" | ||
VerticalOptions="Center" | ||
HorizontalOptions="End"/> | ||
|
||
<RadioButton | ||
Grid.Row="3" | ||
Grid.Column="5" | ||
x:Name="HorizontalOptionsEndRadioButton" | ||
IsChecked="False" | ||
HorizontalOptions="Start" | ||
VerticalOptions="Center" | ||
GroupName="HorizontalLayoutOptions" /> | ||
|
||
<Label | ||
Grid.Row="3" | ||
Grid.Column="6" | ||
FontSize="13" | ||
Text="Fill" | ||
VerticalOptions="Center" | ||
HorizontalOptions="End"/> | ||
|
||
<RadioButton | ||
Grid.Row="3" | ||
Grid.Column="7" | ||
x:Name="HorizontalOptionsFillRadioButton" | ||
IsChecked="False" | ||
HorizontalOptions="Start" | ||
VerticalOptions="Center" | ||
GroupName="HorizontalLayoutOptions" /> | ||
|
||
<Label | ||
Grid.Row="4" | ||
Grid.Column="0" | ||
Grid.ColumnSpan="8" | ||
Text="VerticalOptions" | ||
VerticalOptions="End" | ||
FontAttributes="Bold" /> | ||
|
||
<Label | ||
Grid.Row="5" | ||
Grid.Column="0" | ||
FontSize="13" | ||
Text="Start" | ||
VerticalOptions="Center" | ||
HorizontalOptions="End"/> | ||
|
||
<RadioButton | ||
Grid.Row="5" | ||
Grid.Column="1" | ||
x:Name="VerticalOptionsStartRadioButton" | ||
IsChecked="True" | ||
HorizontalOptions="Start" | ||
VerticalOptions="Center" | ||
GroupName="VerticalLayoutOptions" /> | ||
|
||
<Label | ||
Grid.Row="5" | ||
Grid.Column="2" | ||
FontSize="13" | ||
Text="Center" | ||
VerticalOptions="Center" /> | ||
|
||
<RadioButton | ||
Grid.Row="5" | ||
Grid.Column="3" | ||
x:Name="VerticalOptionsCenterRadioButton" | ||
IsChecked="False" | ||
HorizontalOptions="Start" | ||
VerticalOptions="Center" | ||
GroupName="VerticalLayoutOptions" /> | ||
|
||
<Label | ||
Grid.Row="5" | ||
Grid.Column="4" | ||
FontSize="13" | ||
Text="End" | ||
VerticalOptions="Center" | ||
HorizontalOptions="End"/> | ||
|
||
<RadioButton | ||
Grid.Row="5" | ||
Grid.Column="5" | ||
x:Name="VerticalOptionsEndRadioButton" | ||
IsChecked="False" | ||
HorizontalOptions="Start" | ||
VerticalOptions="Center" | ||
GroupName="VerticalLayoutOptions" /> | ||
|
||
<Label | ||
Grid.Row="5" | ||
Grid.Column="6" | ||
FontSize="13" | ||
Text="Fill" | ||
VerticalOptions="Center" | ||
HorizontalOptions="End"/> | ||
|
||
<RadioButton | ||
Grid.Row="5" | ||
Grid.Column="7" | ||
x:Name="VerticalOptionsFillRadioButton" | ||
IsChecked="False" | ||
HorizontalOptions="Start" | ||
VerticalOptions="Center" | ||
GroupName="VerticalLayoutOptions" /> | ||
|
||
<Button | ||
Grid.Row="6" | ||
Grid.Column="0" | ||
Grid.ColumnSpan="8" | ||
x:Name="ShowPopupButton" | ||
Text="Show Popup" | ||
BackgroundColor="Blue" | ||
TextColor="White" | ||
Margin="0,12,0,0" | ||
VerticalOptions="Start" | ||
Clicked="ShowPopupButtonClicked" /> | ||
</Grid> | ||
</pages:BasePage> |
65 changes: 65 additions & 0 deletions
65
samples/CommunityToolkit.Maui.Sample/Pages/Views/Popup/PopupLayoutAlignmentPage.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using CommunityToolkit.Maui.Sample.ViewModels.Views; | ||
using CommunityToolkit.Maui.Sample.Views.Popups; | ||
using CommunityToolkit.Maui.Views; | ||
|
||
namespace CommunityToolkit.Maui.Sample.Pages.Views; | ||
|
||
public partial class PopupLayoutAlignmentPage : BasePage<PopupLayoutAlignmentViewModel> | ||
{ | ||
public PopupLayoutAlignmentPage(PopupLayoutAlignmentViewModel popupLayoutViewModel) : base(popupLayoutViewModel) | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
void ShowPopupButtonClicked(object sender, EventArgs e) | ||
{ | ||
var redBlueBoxPopup = new RedBlueBoxPopup | ||
{ | ||
Size = new Size(double.Parse(widthEntry.Text), double.Parse(heightEntry.Text)), | ||
}; | ||
|
||
if (VerticalOptionsStartRadioButton.IsChecked) | ||
{ | ||
redBlueBoxPopup.VerticalOptions = Microsoft.Maui.Primitives.LayoutAlignment.Start; | ||
} | ||
else if (VerticalOptionsCenterRadioButton.IsChecked) | ||
{ | ||
redBlueBoxPopup.VerticalOptions = Microsoft.Maui.Primitives.LayoutAlignment.Center; | ||
} | ||
else if (VerticalOptionsEndRadioButton.IsChecked) | ||
{ | ||
redBlueBoxPopup.VerticalOptions = Microsoft.Maui.Primitives.LayoutAlignment.End; | ||
} | ||
else if (VerticalOptionsFillRadioButton.IsChecked) | ||
{ | ||
redBlueBoxPopup.VerticalOptions = Microsoft.Maui.Primitives.LayoutAlignment.Fill; | ||
} | ||
else | ||
{ | ||
throw new InvalidOperationException("VerticalOptions Radio Button Must Be Selected"); | ||
} | ||
|
||
if (HorizontalOptionsStartRadioButton.IsChecked) | ||
{ | ||
redBlueBoxPopup.HorizontalOptions = Microsoft.Maui.Primitives.LayoutAlignment.Start; | ||
} | ||
else if (HorizontalOptionsCenterRadioButton.IsChecked) | ||
{ | ||
redBlueBoxPopup.HorizontalOptions = Microsoft.Maui.Primitives.LayoutAlignment.Center; | ||
} | ||
else if (HorizontalOptionsEndRadioButton.IsChecked) | ||
{ | ||
redBlueBoxPopup.HorizontalOptions = Microsoft.Maui.Primitives.LayoutAlignment.End; | ||
} | ||
else if (HorizontalOptionsFillRadioButton.IsChecked) | ||
{ | ||
redBlueBoxPopup.HorizontalOptions = Microsoft.Maui.Primitives.LayoutAlignment.Fill; | ||
} | ||
else | ||
{ | ||
throw new InvalidOperationException("HorizontalOptions Radio Button Must Be Selected"); | ||
} | ||
|
||
this.ShowPopup(redBlueBoxPopup); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
samples/CommunityToolkit.Maui.Sample/ViewModels/Views/Popup/PopupLayoutAlignmentViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace CommunityToolkit.Maui.Sample.ViewModels.Views; | ||
|
||
public class PopupLayoutAlignmentViewModel : BaseViewModel | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
samples/CommunityToolkit.Maui.Sample/Views/Popups/RedBlueBoxPopup.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<mct:Popup xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:mct="http://schemas.microsoft.com/dotnet/2022/maui/toolkit" | ||
x:Class="CommunityToolkit.Maui.Sample.Views.Popups.RedBlueBoxPopup"> | ||
<Grid VerticalOptions="Fill" HorizontalOptions="Fill" BackgroundColor="Red"> | ||
<Grid WidthRequest="10" HeightRequest="10" VerticalOptions="Start" HorizontalOptions="Start" BackgroundColor="Blue" /> | ||
<Grid WidthRequest="10" HeightRequest="10" VerticalOptions="Start" HorizontalOptions="End" BackgroundColor="Blue" /> | ||
<Grid WidthRequest="10" HeightRequest="10" VerticalOptions="End" HorizontalOptions="Start" BackgroundColor="Blue" /> | ||
<Grid WidthRequest="10" HeightRequest="10" VerticalOptions="End" HorizontalOptions="End" BackgroundColor="Blue" /> | ||
</Grid> | ||
</mct:Popup> |
11 changes: 11 additions & 0 deletions
11
samples/CommunityToolkit.Maui.Sample/Views/Popups/RedBlueBoxPopup.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using CommunityToolkit.Maui.Views; | ||
|
||
namespace CommunityToolkit.Maui.Sample.Views.Popups; | ||
|
||
public partial class RedBlueBoxPopup : Popup | ||
{ | ||
public RedBlueBoxPopup() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.