This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 475
/
PopupPositionViewModel.cs
79 lines (72 loc) · 2.54 KB
/
PopupPositionViewModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System.Windows.Input;
using Xamarin.CommunityToolkit.Extensions;
using Xamarin.CommunityToolkit.Sample.Pages.Views.Popups;
using Xamarin.Forms;
namespace Xamarin.CommunityToolkit.Sample.ViewModels.Views.Popups
{
public class PopupPositionViewModel
{
public PopupPositionViewModel()
{
DisplayPopup = new Command<PopupPosition>(OnDisplayPopup);
}
INavigation Navigation => Application.Current.MainPage.Navigation;
public ICommand DisplayPopup { get; }
void OnDisplayPopup(PopupPosition position)
{
var popup = new SimplePopup();
switch (position)
{
case PopupPosition.TopLeft:
popup.VerticalOptions = new LayoutOptions(LayoutAlignment.Start, true);
popup.HorizontalOptions = new LayoutOptions(LayoutAlignment.Start, true);
break;
case PopupPosition.Top:
popup.VerticalOptions = new LayoutOptions(LayoutAlignment.Start, true);
popup.HorizontalOptions = new LayoutOptions(LayoutAlignment.Center, true);
break;
case PopupPosition.TopRight:
popup.VerticalOptions = new LayoutOptions(LayoutAlignment.Start, true);
popup.HorizontalOptions = new LayoutOptions(LayoutAlignment.End, true);
break;
case PopupPosition.Left:
popup.VerticalOptions = new LayoutOptions(LayoutAlignment.Center, true);
popup.HorizontalOptions = new LayoutOptions(LayoutAlignment.Start, true);
break;
case PopupPosition.Center:
popup.VerticalOptions = new LayoutOptions(LayoutAlignment.Center, true);
popup.HorizontalOptions = new LayoutOptions(LayoutAlignment.Center, true);
break;
case PopupPosition.Right:
popup.VerticalOptions = new LayoutOptions(LayoutAlignment.Center, true);
popup.HorizontalOptions = new LayoutOptions(LayoutAlignment.End, true);
break;
case PopupPosition.BottomLeft:
popup.VerticalOptions = new LayoutOptions(LayoutAlignment.End, true);
popup.HorizontalOptions = new LayoutOptions(LayoutAlignment.Start, true);
break;
case PopupPosition.Bottom:
popup.VerticalOptions = new LayoutOptions(LayoutAlignment.End, true);
popup.HorizontalOptions = new LayoutOptions(LayoutAlignment.Center, true);
break;
case PopupPosition.BottomRight:
popup.VerticalOptions = new LayoutOptions(LayoutAlignment.End, true);
popup.HorizontalOptions = new LayoutOptions(LayoutAlignment.End, true);
break;
}
Navigation.ShowPopup(popup);
}
public enum PopupPosition
{
TopLeft = 0,
Top = 1,
TopRight = 2,
Left = 3,
Center = 4,
Right = 5,
BottomLeft = 6,
Bottom = 7,
BottomRight = 8
}
}
}