Skip to content

Commit e8966e0

Browse files
authored
Merge pull request #89 from egvijayanand/working
Version label and Styling
2 parents d143a7f + 910540d commit e8966e0

File tree

6 files changed

+154
-101
lines changed

6 files changed

+154
-101
lines changed

src/NET_8/UnifiedDateCalculator/DateCalculator.Forms/App.xaml

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
<x:Double x:Key="ItemSpacing">5</x:Double>
1414

15+
<!--<Color x:Key="Primary">#03A9F4</Color>-->
1516
<Color x:Key="Primary">#3700B3</Color>
1617
<Color x:Key="White">White</Color>
1718
<Color x:Key="Black">Black</Color>
@@ -40,6 +41,10 @@
4041
<Setter Property="FontSize" Value="{StaticResource AppFontSize}" />
4142
</Style>
4243

44+
<Style x:Key="Footer" TargetType="Grid">
45+
<Setter Property="BackgroundColor" Value="{AppThemeBinding Dark={StaticResource BackgroundDark}, Light={StaticResource Primary}}" />
46+
</Style>
47+
4348
<Style x:Key="Caption" TargetType="Label">
4449
<Setter Property="TextColor" Value="{AppThemeBinding Dark={StaticResource LightGray}, Light={StaticResource DarkGray}}" />
4550
</Style>
@@ -61,4 +66,4 @@
6166
</Style>
6267
</ResourceDictionary>
6368
</Application.Resources>
64-
</Application>
69+
</Application>

src/NET_8/UnifiedDateCalculator/DateCalculator.Forms/AppShell.xaml

+20-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,26 @@
1313
The overall app visual hierarchy is defined here, along with navigation.
1414
Ensure atleast a Flyout item or a TabBar is defined for Shell to work
1515
-->
16-
<Shell.Resources />
16+
<Shell.Resources>
17+
<Style
18+
x:Key="BaseStyle"
19+
TargetType="Element">
20+
<Setter Property="Shell.BackgroundColor" Value="{StaticResource Primary}" />
21+
<Setter Property="Shell.ForegroundColor" Value="{StaticResource White}" />
22+
<Setter Property="Shell.TitleColor" Value="{StaticResource White}" />
23+
<Setter Property="Shell.DisabledColor" Value="{AppThemeBinding Light={StaticResource LightGray}, Dark={StaticResource DarkGray}}" />
24+
<Setter Property="Shell.UnselectedColor" Value="{AppThemeBinding Light={StaticResource LightGray}, Dark={StaticResource DarkGray}}" />
25+
<Setter Property="Shell.NavBarHasShadow" Value="True" />
26+
<Setter Property="Shell.TabBarBackgroundColor" Value="{StaticResource Primary}" />
27+
<Setter Property="Shell.TabBarForegroundColor" Value="{StaticResource White}" />
28+
<Setter Property="Shell.TabBarTitleColor" Value="{StaticResource White}" />
29+
<Setter Property="Shell.TabBarUnselectedColor" Value="{AppThemeBinding Light={StaticResource LightGray}, Dark={StaticResource DarkGray}}" />
30+
</Style>
31+
<Style
32+
ApplyToDerivedTypes="True"
33+
BasedOn="{StaticResource BaseStyle}"
34+
TargetType="ShellItem" />
35+
</Shell.Resources>
1736
<!--
1837
When the Flyout is visible this defines the content to display in the flyout.
1938
FlyoutDisplayOptions="AsMultipleItems" will create a separate flyout item for each child element

src/NET_8/UnifiedDateCalculator/DateCalculator.Maui/App.xaml

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
<Setter Property="Padding" Value="{OnPlatform iOS={StaticResource ApplePadding}, Default={StaticResource DefaultPadding}}" />
2626
</Style>
2727

28+
<Style x:Key="Footer" TargetType="Grid">
29+
<Setter Property="BackgroundColor" Value="{AppThemeBinding Dark={StaticResource BackgroundDark}, Light={StaticResource Primary}}" />
30+
</Style>
31+
2832
<Style x:Key="Caption" TargetType="Label">
2933
<Setter Property="TextColor" Value="{AppThemeBinding Dark={StaticResource LightGray}, Light={StaticResource DarkGray}}" />
3034
</Style>

src/NET_8/UnifiedDateCalculator/DateCalculator.UI/DateCalculator.UI.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
<PackageReference Include="Xamarin.Forms" Version="5.*" />
3737
<PackageReference Include="Xamarin.CommunityToolkit" Version="2.*" />
3838
<PackageReference Include="Xamarin.CommunityToolkit.Markup" Version="2.*" />
39+
<PackageReference Include="PolySharp" Version="1.*">
40+
<PrivateAssets>all</PrivateAssets>
41+
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
42+
</PackageReference>
3943
</ItemGroup>
4044

4145
<!-- .NET MAUI NuGet packages -->

src/NET_8/UnifiedDateCalculator/DateCalculator.UI/Imports.maui.cs

+2
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@
1414
global using Microsoft.Maui.Networking;
1515
global using Microsoft.Maui.Storage;
1616
global using static Microsoft.Maui.Graphics.Colors;
17+
18+
global using static CommunityToolkit.Maui.Markup.GridRowsColumns;

src/NET_8/UnifiedDateCalculator/DateCalculator.UI/Views/DatePage.shared.cs

+118-99
Original file line numberDiff line numberDiff line change
@@ -1,159 +1,178 @@
11
using DateCalculator.ViewModels;
2+
using System.Diagnostics.CodeAnalysis;
3+
using System.Reflection;
24

35
namespace DateCalculator.UI.Views
46
{
57
public partial class DatePage : ContentPage
68
{
9+
private Label versionLabel;
10+
711
public DatePage()
812
{
913
InitializeComponent();
1014
//ViewModel = new DateViewModel();
1115
//BindingContext = ViewModel;
1216
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
1325
}
1426

27+
[MemberNotNull(nameof(versionLabel))]
1528
private void InitializeComponent()
1629
{
1730
this.Bindv2(TitleProperty, static (DateViewModel vm) => vm.Title);
18-
this.Padding(20);
1931
Resources.Add("InverseBoolConverter", new InvertedBoolConverter());
2032
Resources.Add("IntToBoolConverter", new IntToBoolConverter());
21-
Content = new StackLayout()
33+
Content = new Grid()
2234
{
23-
Spacing = 30,
35+
RowDefinitions = Rows.Define(Star, 40),
2436
Children =
2537
{
26-
new Picker().Start()
27-
.Bindv2(Picker.ItemsSourceProperty, static (DateViewModel vm) => vm.Options)
28-
.Bindv2(static (DateViewModel vm) => vm.SelectedOption),
2938
new StackLayout()
3039
{
3140
Children =
3241
{
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()
3947
{
40-
Behaviors =
48+
Children =
4149
{
42-
new EventToCommandBehavior()
50+
new Label()
4351
{
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),
4664
},
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()
6067
{
61-
Behaviors =
68+
Children =
6269
{
63-
new EventToCommandBehavior()
70+
new Label()
6471
{
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),
6784
},
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),
7587
new StackLayout()
7688
{
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,
8689
Children =
8790
{
8891
new StackLayout()
8992
{
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)),
10098
new StackLayout()
10199
{
100+
Orientation = StackOrientation.Horizontal,
102101
Children =
103102
{
104-
new Label()
103+
new StackLayout()
105104
{
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+
},
107111
},
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()
117113
{
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+
},
119120
},
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()
129122
{
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+
},
131139
},
132-
new Picker().Bindv2(Picker.ItemsSourceProperty, static(DateViewModel vm) => vm.Range)
133-
.Bindv2(static(DateViewModel vm) => vm.SelectedDay),
134140
},
135-
},
141+
}.Spacing(20),
136142
},
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()
141165
{
166+
Style = AppStyle("Footer"),
142167
Children =
143168
{
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),
153172
},
154-
}.Start(),
173+
}.Row(1)
155174
}
156-
}.Top();
175+
};
157176
}
158177

159178
//public DateViewModel ViewModel { get; private set; }

0 commit comments

Comments
 (0)