|
1 | 1 | using DateCalculator.ViewModels;
|
| 2 | +using System.Diagnostics.CodeAnalysis; |
| 3 | +using System.Reflection; |
2 | 4 |
|
3 | 5 | namespace DateCalculator.UI.Views
|
4 | 6 | {
|
5 | 7 | public partial class DatePage : ContentPage
|
6 | 8 | {
|
| 9 | + private Label versionLabel; |
| 10 | + |
7 | 11 | public DatePage()
|
8 | 12 | {
|
9 | 13 | InitializeComponent();
|
10 | 14 | //ViewModel = new DateViewModel();
|
11 | 15 | //BindingContext = ViewModel;
|
12 | 16 | BindingContext = new DateViewModel();
|
| 17 | + var version = typeof(Application).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion; |
| 18 | +#if MAUI |
| 19 | + versionLabel.Text = $".NET MAUI ver. {version?[..version.IndexOf('+')]}"; |
| 20 | +#elif FORMS |
| 21 | + versionLabel.Text = $"Xamarin.Forms ver. {version?[..version.IndexOf('+')]}"; |
| 22 | +#else |
| 23 | + versionLabel.Text = string.Empty; |
| 24 | +#endif |
13 | 25 | }
|
14 | 26 |
|
| 27 | + [MemberNotNull(nameof(versionLabel))] |
15 | 28 | private void InitializeComponent()
|
16 | 29 | {
|
17 | 30 | this.Bindv2(TitleProperty, static (DateViewModel vm) => vm.Title);
|
18 |
| - this.Padding(20); |
19 | 31 | Resources.Add("InverseBoolConverter", new InvertedBoolConverter());
|
20 | 32 | Resources.Add("IntToBoolConverter", new IntToBoolConverter());
|
21 |
| - Content = new StackLayout() |
| 33 | + Content = new Grid() |
22 | 34 | {
|
23 |
| - Spacing = 30, |
| 35 | + RowDefinitions = Rows.Define(Star, 40), |
24 | 36 | Children =
|
25 | 37 | {
|
26 |
| - new Picker().Start() |
27 |
| - .Bindv2(Picker.ItemsSourceProperty, static (DateViewModel vm) => vm.Options) |
28 |
| - .Bindv2(static (DateViewModel vm) => vm.SelectedOption), |
29 | 38 | new StackLayout()
|
30 | 39 | {
|
31 | 40 | Children =
|
32 | 41 | {
|
33 |
| - new Label() |
34 |
| - { |
35 |
| - Style = AppStyle("Caption"), |
36 |
| - Text = "From", |
37 |
| - }, |
38 |
| - new DatePicker() |
| 42 | + new Picker() |
| 43 | + .Start() |
| 44 | + .Bindv2(Picker.ItemsSourceProperty, static (DateViewModel vm) => vm.Options) |
| 45 | + .Bindv2(static (DateViewModel vm) => vm.SelectedOption), |
| 46 | + new StackLayout() |
39 | 47 | {
|
40 |
| - Behaviors = |
| 48 | + Children = |
41 | 49 | {
|
42 |
| - new EventToCommandBehavior() |
| 50 | + new Label() |
43 | 51 | {
|
44 |
| - EventName = nameof(DatePicker.DateSelected), |
45 |
| - }.BindCommandv2(static (DateViewModel vm) => vm.DateDiffCommand), |
| 52 | + Style = AppStyle("Caption") |
| 53 | + }.Text("From"), |
| 54 | + new DatePicker() |
| 55 | + { |
| 56 | + Behaviors = |
| 57 | + { |
| 58 | + new EventToCommandBehavior() |
| 59 | + { |
| 60 | + EventName = nameof(DatePicker.DateSelected), |
| 61 | + }.BindCommandv2(static (DateViewModel vm) => vm.DateDiffCommand), |
| 62 | + }, |
| 63 | + }.Bindv2(static (DateViewModel vm) => vm.StartDate), |
46 | 64 | },
|
47 |
| - }.Bindv2(static (DateViewModel vm) => vm.StartDate), |
48 |
| - }, |
49 |
| - }.Start(), |
50 |
| - new StackLayout() |
51 |
| - { |
52 |
| - Children = |
53 |
| - { |
54 |
| - new Label() |
55 |
| - { |
56 |
| - Style = AppStyle("Caption"), |
57 |
| - Text = "To", |
58 |
| - }, |
59 |
| - new DatePicker() |
| 65 | + }.Start(), |
| 66 | + new StackLayout() |
60 | 67 | {
|
61 |
| - Behaviors = |
| 68 | + Children = |
62 | 69 | {
|
63 |
| - new EventToCommandBehavior() |
| 70 | + new Label() |
64 | 71 | {
|
65 |
| - EventName = nameof(DatePicker.DateSelected), |
66 |
| - }.BindCommandv2(static (DateViewModel vm) => vm.DateDiffCommand), |
| 72 | + Style = AppStyle("Caption") |
| 73 | + }.Text("To"), |
| 74 | + new DatePicker() |
| 75 | + { |
| 76 | + Behaviors = |
| 77 | + { |
| 78 | + new EventToCommandBehavior() |
| 79 | + { |
| 80 | + EventName = nameof(DatePicker.DateSelected), |
| 81 | + }.BindCommandv2(static (DateViewModel vm) => vm.DateDiffCommand), |
| 82 | + }, |
| 83 | + }.Bindv2(static (DateViewModel vm) => vm.EndDate), |
67 | 84 | },
|
68 |
| - }.Bindv2(static (DateViewModel vm) => vm.EndDate), |
69 |
| - }, |
70 |
| - }.Start().Bindv2(IsVisibleProperty, static(DateViewModel vm) => vm.DiffMode), |
71 |
| - new StackLayout() |
72 |
| - { |
73 |
| - Children = |
74 |
| - { |
| 85 | + }.Start() |
| 86 | + .Bindv2(IsVisibleProperty, static(DateViewModel vm) => vm.DiffMode), |
75 | 87 | new StackLayout()
|
76 | 88 | {
|
77 |
| - Orientation = StackOrientation.Horizontal, |
78 |
| - }.RadioButtonGroupName("modes") |
79 |
| - .Bindv2(RadioButtonGroup.SelectedValueProperty, static(DateViewModel vm) => vm.SelectedMode) |
80 |
| - .ItemsSource(["Add", "Subtract"]) |
81 |
| - .ItemTemplate(() => new RadioButton().Bind(RadioButton.ContentProperty, Binding.SelfPath).Bind(RadioButton.ValueProperty, Binding.SelfPath)), |
82 |
| - new StackLayout() |
83 |
| - { |
84 |
| - Orientation = StackOrientation.Horizontal, |
85 |
| - Spacing = 20, |
86 | 89 | Children =
|
87 | 90 | {
|
88 | 91 | new StackLayout()
|
89 | 92 | {
|
90 |
| - Children = |
91 |
| - { |
92 |
| - new Label() |
93 |
| - { |
94 |
| - Text = "Years", |
95 |
| - }, |
96 |
| - new Picker().Bindv2(Picker.ItemsSourceProperty,static(DateViewModel vm) => vm.Range) |
97 |
| - .Bindv2(static(DateViewModel vm) => vm.SelectedYear), |
98 |
| - }, |
99 |
| - }, |
| 93 | + Orientation = StackOrientation.Horizontal, |
| 94 | + }.RadioButtonGroupName("modes") |
| 95 | + .Bindv2(RadioButtonGroup.SelectedValueProperty, static(DateViewModel vm) => vm.SelectedMode) |
| 96 | + .ItemsSource(["Add", "Subtract"]) |
| 97 | + .ItemTemplate(() => new RadioButton().Bind(RadioButton.ContentProperty).Bind(RadioButton.ValueProperty)), |
100 | 98 | new StackLayout()
|
101 | 99 | {
|
| 100 | + Orientation = StackOrientation.Horizontal, |
102 | 101 | Children =
|
103 | 102 | {
|
104 |
| - new Label() |
| 103 | + new StackLayout() |
105 | 104 | {
|
106 |
| - Text = "Months", |
| 105 | + Children = |
| 106 | + { |
| 107 | + new Label().Text("Years"), |
| 108 | + new Picker().Bindv2(Picker.ItemsSourceProperty, static(DateViewModel vm) => vm.Range) |
| 109 | + .Bindv2(static(DateViewModel vm) => vm.SelectedYear), |
| 110 | + }, |
107 | 111 | },
|
108 |
| - new Picker().Bindv2(Picker.ItemsSourceProperty, static(DateViewModel vm) => vm.Range) |
109 |
| - .Bindv2(static(DateViewModel vm) => vm.SelectedMonth), |
110 |
| - }, |
111 |
| - }, |
112 |
| - new StackLayout() |
113 |
| - { |
114 |
| - Children = |
115 |
| - { |
116 |
| - new Label() |
| 112 | + new StackLayout() |
117 | 113 | {
|
118 |
| - Text = "Weeks", |
| 114 | + Children = |
| 115 | + { |
| 116 | + new Label().Text("Months"), |
| 117 | + new Picker().Bindv2(Picker.ItemsSourceProperty, static(DateViewModel vm) => vm.Range) |
| 118 | + .Bindv2(static(DateViewModel vm) => vm.SelectedMonth), |
| 119 | + }, |
119 | 120 | },
|
120 |
| - new Picker().Bindv2(Picker.ItemsSourceProperty, static(DateViewModel vm) => vm.Range) |
121 |
| - .Bindv2(static(DateViewModel vm) => vm.SelectedWeek), |
122 |
| - }, |
123 |
| - }, |
124 |
| - new StackLayout() |
125 |
| - { |
126 |
| - Children = |
127 |
| - { |
128 |
| - new Label() |
| 121 | + new StackLayout() |
129 | 122 | {
|
130 |
| - Text = "Days", |
| 123 | + Children = |
| 124 | + { |
| 125 | + new Label().Text("Weeks"), |
| 126 | + new Picker().Bindv2(Picker.ItemsSourceProperty, static(DateViewModel vm) => vm.Range) |
| 127 | + .Bindv2(static(DateViewModel vm) => vm.SelectedWeek), |
| 128 | + }, |
| 129 | + }, |
| 130 | + new StackLayout() |
| 131 | + { |
| 132 | + Children = |
| 133 | + { |
| 134 | + new Label().Text("Days"), |
| 135 | + new Picker() |
| 136 | + .Bindv2(Picker.ItemsSourceProperty, static(DateViewModel vm) => vm.Range) |
| 137 | + .Bindv2(static(DateViewModel vm) => vm.SelectedDay), |
| 138 | + }, |
131 | 139 | },
|
132 |
| - new Picker().Bindv2(Picker.ItemsSourceProperty, static(DateViewModel vm) => vm.Range) |
133 |
| - .Bindv2(static(DateViewModel vm) => vm.SelectedDay), |
134 | 140 | },
|
135 |
| - }, |
| 141 | + }.Spacing(20), |
136 | 142 | },
|
137 |
| - }, |
138 |
| - }, |
139 |
| - }.Start().Bindv2(IsVisibleProperty, static(DateViewModel vm) => vm.DiffModeInverse), |
140 |
| - new StackLayout() |
| 143 | + }.Start().Bindv2(IsVisibleProperty, static(DateViewModel vm) => vm.DiffModeInverse), |
| 144 | + new StackLayout() |
| 145 | + { |
| 146 | + Children = |
| 147 | + { |
| 148 | + new Label() |
| 149 | + { |
| 150 | + Style = AppStyle("Caption"), |
| 151 | + }.Bindv2(static (DateViewModel vm) => vm.ResultCaption), |
| 152 | + new Label() |
| 153 | + { |
| 154 | + Style = AppStyle("BoldText"), |
| 155 | + }.Bindv2(static(DateViewModel vm) => vm.DiffResult), |
| 156 | + new Label().Bindv2(static(DateViewModel vm) => vm.DiffInDays), |
| 157 | + }, |
| 158 | + }.Start(), |
| 159 | + } |
| 160 | + }.Row(0) |
| 161 | + .Top() |
| 162 | + .Spacing(30) |
| 163 | + .Padding(20), |
| 164 | + new Grid() |
141 | 165 | {
|
| 166 | + Style = AppStyle("Footer"), |
142 | 167 | Children =
|
143 | 168 | {
|
144 |
| - new Label() |
145 |
| - { |
146 |
| - Style = AppStyle("Caption"), |
147 |
| - }.Bindv2(static (DateViewModel vm) => vm.ResultCaption), |
148 |
| - new Label() |
149 |
| - { |
150 |
| - Style = AppStyle("BoldText"), |
151 |
| - }.Bindv2(static(DateViewModel vm) => vm.DiffResult), |
152 |
| - new Label().Bindv2(static(DateViewModel vm) => vm.DiffInDays), |
| 169 | + new Label().Center() |
| 170 | + .TextColor(AppColor("White")) |
| 171 | + .Assign(out versionLabel), |
153 | 172 | },
|
154 |
| - }.Start(), |
| 173 | + }.Row(1) |
155 | 174 | }
|
156 |
| - }.Top(); |
| 175 | + }; |
157 | 176 | }
|
158 | 177 |
|
159 | 178 | //public DateViewModel ViewModel { get; private set; }
|
|
0 commit comments