Skip to content

Commit

Permalink
Merge pull request #89 from egvijayanand/working
Browse files Browse the repository at this point in the history
Version label and Styling
  • Loading branch information
egvijayanand authored Jul 24, 2024
2 parents d143a7f + 910540d commit e8966e0
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

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

<!--<Color x:Key="Primary">#03A9F4</Color>-->
<Color x:Key="Primary">#3700B3</Color>
<Color x:Key="White">White</Color>
<Color x:Key="Black">Black</Color>
Expand Down Expand Up @@ -40,6 +41,10 @@
<Setter Property="FontSize" Value="{StaticResource AppFontSize}" />
</Style>

<Style x:Key="Footer" TargetType="Grid">
<Setter Property="BackgroundColor" Value="{AppThemeBinding Dark={StaticResource BackgroundDark}, Light={StaticResource Primary}}" />
</Style>

<Style x:Key="Caption" TargetType="Label">
<Setter Property="TextColor" Value="{AppThemeBinding Dark={StaticResource LightGray}, Light={StaticResource DarkGray}}" />
</Style>
Expand All @@ -61,4 +66,4 @@
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>
</Application>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,26 @@
The overall app visual hierarchy is defined here, along with navigation.
Ensure atleast a Flyout item or a TabBar is defined for Shell to work
-->
<Shell.Resources />
<Shell.Resources>
<Style
x:Key="BaseStyle"
TargetType="Element">
<Setter Property="Shell.BackgroundColor" Value="{StaticResource Primary}" />
<Setter Property="Shell.ForegroundColor" Value="{StaticResource White}" />
<Setter Property="Shell.TitleColor" Value="{StaticResource White}" />
<Setter Property="Shell.DisabledColor" Value="{AppThemeBinding Light={StaticResource LightGray}, Dark={StaticResource DarkGray}}" />
<Setter Property="Shell.UnselectedColor" Value="{AppThemeBinding Light={StaticResource LightGray}, Dark={StaticResource DarkGray}}" />
<Setter Property="Shell.NavBarHasShadow" Value="True" />
<Setter Property="Shell.TabBarBackgroundColor" Value="{StaticResource Primary}" />
<Setter Property="Shell.TabBarForegroundColor" Value="{StaticResource White}" />
<Setter Property="Shell.TabBarTitleColor" Value="{StaticResource White}" />
<Setter Property="Shell.TabBarUnselectedColor" Value="{AppThemeBinding Light={StaticResource LightGray}, Dark={StaticResource DarkGray}}" />
</Style>
<Style
ApplyToDerivedTypes="True"
BasedOn="{StaticResource BaseStyle}"
TargetType="ShellItem" />
</Shell.Resources>
<!--
When the Flyout is visible this defines the content to display in the flyout.
FlyoutDisplayOptions="AsMultipleItems" will create a separate flyout item for each child element
Expand Down
4 changes: 4 additions & 0 deletions src/NET_8/UnifiedDateCalculator/DateCalculator.Maui/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<Setter Property="Padding" Value="{OnPlatform iOS={StaticResource ApplePadding}, Default={StaticResource DefaultPadding}}" />
</Style>

<Style x:Key="Footer" TargetType="Grid">
<Setter Property="BackgroundColor" Value="{AppThemeBinding Dark={StaticResource BackgroundDark}, Light={StaticResource Primary}}" />
</Style>

<Style x:Key="Caption" TargetType="Label">
<Setter Property="TextColor" Value="{AppThemeBinding Dark={StaticResource LightGray}, Light={StaticResource DarkGray}}" />
</Style>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
<PackageReference Include="Xamarin.Forms" Version="5.*" />
<PackageReference Include="Xamarin.CommunityToolkit" Version="2.*" />
<PackageReference Include="Xamarin.CommunityToolkit.Markup" Version="2.*" />
<PackageReference Include="PolySharp" Version="1.*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<!-- .NET MAUI NuGet packages -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
global using Microsoft.Maui.Networking;
global using Microsoft.Maui.Storage;
global using static Microsoft.Maui.Graphics.Colors;

global using static CommunityToolkit.Maui.Markup.GridRowsColumns;
Original file line number Diff line number Diff line change
@@ -1,159 +1,178 @@
using DateCalculator.ViewModels;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;

namespace DateCalculator.UI.Views
{
public partial class DatePage : ContentPage
{
private Label versionLabel;

public DatePage()
{
InitializeComponent();
//ViewModel = new DateViewModel();
//BindingContext = ViewModel;
BindingContext = new DateViewModel();
var version = typeof(Application).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
#if MAUI
versionLabel.Text = $".NET MAUI ver. {version?[..version.IndexOf('+')]}";
#elif FORMS
versionLabel.Text = $"Xamarin.Forms ver. {version?[..version.IndexOf('+')]}";
#else
versionLabel.Text = string.Empty;
#endif
}

[MemberNotNull(nameof(versionLabel))]
private void InitializeComponent()
{
this.Bindv2(TitleProperty, static (DateViewModel vm) => vm.Title);
this.Padding(20);
Resources.Add("InverseBoolConverter", new InvertedBoolConverter());
Resources.Add("IntToBoolConverter", new IntToBoolConverter());
Content = new StackLayout()
Content = new Grid()
{
Spacing = 30,
RowDefinitions = Rows.Define(Star, 40),
Children =
{
new Picker().Start()
.Bindv2(Picker.ItemsSourceProperty, static (DateViewModel vm) => vm.Options)
.Bindv2(static (DateViewModel vm) => vm.SelectedOption),
new StackLayout()
{
Children =
{
new Label()
{
Style = AppStyle("Caption"),
Text = "From",
},
new DatePicker()
new Picker()
.Start()
.Bindv2(Picker.ItemsSourceProperty, static (DateViewModel vm) => vm.Options)
.Bindv2(static (DateViewModel vm) => vm.SelectedOption),
new StackLayout()
{
Behaviors =
Children =
{
new EventToCommandBehavior()
new Label()
{
EventName = nameof(DatePicker.DateSelected),
}.BindCommandv2(static (DateViewModel vm) => vm.DateDiffCommand),
Style = AppStyle("Caption")
}.Text("From"),
new DatePicker()
{
Behaviors =
{
new EventToCommandBehavior()
{
EventName = nameof(DatePicker.DateSelected),
}.BindCommandv2(static (DateViewModel vm) => vm.DateDiffCommand),
},
}.Bindv2(static (DateViewModel vm) => vm.StartDate),
},
}.Bindv2(static (DateViewModel vm) => vm.StartDate),
},
}.Start(),
new StackLayout()
{
Children =
{
new Label()
{
Style = AppStyle("Caption"),
Text = "To",
},
new DatePicker()
}.Start(),
new StackLayout()
{
Behaviors =
Children =
{
new EventToCommandBehavior()
new Label()
{
EventName = nameof(DatePicker.DateSelected),
}.BindCommandv2(static (DateViewModel vm) => vm.DateDiffCommand),
Style = AppStyle("Caption")
}.Text("To"),
new DatePicker()
{
Behaviors =
{
new EventToCommandBehavior()
{
EventName = nameof(DatePicker.DateSelected),
}.BindCommandv2(static (DateViewModel vm) => vm.DateDiffCommand),
},
}.Bindv2(static (DateViewModel vm) => vm.EndDate),
},
}.Bindv2(static (DateViewModel vm) => vm.EndDate),
},
}.Start().Bindv2(IsVisibleProperty, static(DateViewModel vm) => vm.DiffMode),
new StackLayout()
{
Children =
{
}.Start()
.Bindv2(IsVisibleProperty, static(DateViewModel vm) => vm.DiffMode),
new StackLayout()
{
Orientation = StackOrientation.Horizontal,
}.RadioButtonGroupName("modes")
.Bindv2(RadioButtonGroup.SelectedValueProperty, static(DateViewModel vm) => vm.SelectedMode)
.ItemsSource(["Add", "Subtract"])
.ItemTemplate(() => new RadioButton().Bind(RadioButton.ContentProperty, Binding.SelfPath).Bind(RadioButton.ValueProperty, Binding.SelfPath)),
new StackLayout()
{
Orientation = StackOrientation.Horizontal,
Spacing = 20,
Children =
{
new StackLayout()
{
Children =
{
new Label()
{
Text = "Years",
},
new Picker().Bindv2(Picker.ItemsSourceProperty,static(DateViewModel vm) => vm.Range)
.Bindv2(static(DateViewModel vm) => vm.SelectedYear),
},
},
Orientation = StackOrientation.Horizontal,
}.RadioButtonGroupName("modes")
.Bindv2(RadioButtonGroup.SelectedValueProperty, static(DateViewModel vm) => vm.SelectedMode)
.ItemsSource(["Add", "Subtract"])
.ItemTemplate(() => new RadioButton().Bind(RadioButton.ContentProperty).Bind(RadioButton.ValueProperty)),
new StackLayout()
{
Orientation = StackOrientation.Horizontal,
Children =
{
new Label()
new StackLayout()
{
Text = "Months",
Children =
{
new Label().Text("Years"),
new Picker().Bindv2(Picker.ItemsSourceProperty, static(DateViewModel vm) => vm.Range)
.Bindv2(static(DateViewModel vm) => vm.SelectedYear),
},
},
new Picker().Bindv2(Picker.ItemsSourceProperty, static(DateViewModel vm) => vm.Range)
.Bindv2(static(DateViewModel vm) => vm.SelectedMonth),
},
},
new StackLayout()
{
Children =
{
new Label()
new StackLayout()
{
Text = "Weeks",
Children =
{
new Label().Text("Months"),
new Picker().Bindv2(Picker.ItemsSourceProperty, static(DateViewModel vm) => vm.Range)
.Bindv2(static(DateViewModel vm) => vm.SelectedMonth),
},
},
new Picker().Bindv2(Picker.ItemsSourceProperty, static(DateViewModel vm) => vm.Range)
.Bindv2(static(DateViewModel vm) => vm.SelectedWeek),
},
},
new StackLayout()
{
Children =
{
new Label()
new StackLayout()
{
Text = "Days",
Children =
{
new Label().Text("Weeks"),
new Picker().Bindv2(Picker.ItemsSourceProperty, static(DateViewModel vm) => vm.Range)
.Bindv2(static(DateViewModel vm) => vm.SelectedWeek),
},
},
new StackLayout()
{
Children =
{
new Label().Text("Days"),
new Picker()
.Bindv2(Picker.ItemsSourceProperty, static(DateViewModel vm) => vm.Range)
.Bindv2(static(DateViewModel vm) => vm.SelectedDay),
},
},
new Picker().Bindv2(Picker.ItemsSourceProperty, static(DateViewModel vm) => vm.Range)
.Bindv2(static(DateViewModel vm) => vm.SelectedDay),
},
},
}.Spacing(20),
},
},
},
}.Start().Bindv2(IsVisibleProperty, static(DateViewModel vm) => vm.DiffModeInverse),
new StackLayout()
}.Start().Bindv2(IsVisibleProperty, static(DateViewModel vm) => vm.DiffModeInverse),
new StackLayout()
{
Children =
{
new Label()
{
Style = AppStyle("Caption"),
}.Bindv2(static (DateViewModel vm) => vm.ResultCaption),
new Label()
{
Style = AppStyle("BoldText"),
}.Bindv2(static(DateViewModel vm) => vm.DiffResult),
new Label().Bindv2(static(DateViewModel vm) => vm.DiffInDays),
},
}.Start(),
}
}.Row(0)
.Top()
.Spacing(30)
.Padding(20),
new Grid()
{
Style = AppStyle("Footer"),
Children =
{
new Label()
{
Style = AppStyle("Caption"),
}.Bindv2(static (DateViewModel vm) => vm.ResultCaption),
new Label()
{
Style = AppStyle("BoldText"),
}.Bindv2(static(DateViewModel vm) => vm.DiffResult),
new Label().Bindv2(static(DateViewModel vm) => vm.DiffInDays),
new Label().Center()
.TextColor(AppColor("White"))
.Assign(out versionLabel),
},
}.Start(),
}.Row(1)
}
}.Top();
};
}

//public DateViewModel ViewModel { get; private set; }
Expand Down

0 comments on commit e8966e0

Please sign in to comment.