Skip to content

Commit

Permalink
windows layout cleanup, dark mode
Browse files Browse the repository at this point in the history
Extends content into title bar disabled so we can get a bar to drag the window until the Shell PR is merged for this.

started on theme modes.
  • Loading branch information
davidortinau committed Jan 14, 2022
1 parent e2fb960 commit 6c2849f
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 38 deletions.
4 changes: 2 additions & 2 deletions src/WeatherTwentyOne/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
FlyoutBackgroundColor="{StaticResource Background_Mid}"
FlyoutBehavior="{OnIdiom Phone=Disabled, Default=Locked}">

<Shell.FlyoutHeaderTemplate>
<!--<Shell.FlyoutHeaderTemplate>
<DataTemplate>
<BoxView HeightRequest="68"/>
</DataTemplate>
</Shell.FlyoutHeaderTemplate>
</Shell.FlyoutHeaderTemplate>-->

<Shell.FlyoutFooterTemplate>
<DataTemplate>
Expand Down
1 change: 1 addition & 0 deletions src/WeatherTwentyOne/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static MauiApp CreateMauiApp()
WindowExtensions.Hwnd = args.Hwnd;
WindowExtensions.SetIcon("Platforms/Windows/trayicon.ico");
}
app.ExtendsContentIntoTitleBar = false;
}));
#endif
});
Expand Down
2 changes: 1 addition & 1 deletion src/WeatherTwentyOne/Pages/HomePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private void SetupAppActions()
try
{
#if WINDOWS
AppActions.IconDirectory = Application.Current.On<WindowsConfiguration>().GetImageDirectory();
AppActions.IconDirectory = Application.Current.On<WindowsConfiguration>().GetImageDirectory();
#endif
AppActions.SetAsync(
new AppAction("current_info", "Check Current Weather", icon: "current_info"),
Expand Down
45 changes: 26 additions & 19 deletions src/WeatherTwentyOne/Pages/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,18 @@

<Label Text="Units" class="SectionTitle"/>

<Grid RowDefinitions="*,*">
<Grid.GestureRecognizers>
<TapGestureRecognizer Command="{Binding SelectUnits}"
CommandParameter="imperial"/>
</Grid.GestureRecognizers>
<Grid RowDefinitions="30,30">
<Grid.GestureRecognizers>
<TapGestureRecognizer Command="{Binding SelectUnits}"
CommandParameter="imperial"/>
</Grid.GestureRecognizers>
<Label Grid.Row="0" Text="Imperial" class="Subhead"/>
<Label Grid.Row="1"
Text="˚F / mph / miles / inches" class="SubContent"/>
<Image
x:Name="Imperial"
Grid.RowSpan="2"
Aspect="Center"
IsVisible="{Binding IsImperial}"
Source="checkmark_icon.png"
HorizontalOptions="End"
Expand All @@ -63,7 +64,7 @@
</Grid>
<BoxView class="HRule"/>

<Grid RowDefinitions="*,*">
<Grid RowDefinitions="30,30">
<Grid.GestureRecognizers>
<TapGestureRecognizer Command="{Binding SelectUnits}"
CommandParameter="metric"/>
Expand All @@ -74,14 +75,15 @@
Text="˚C / kmh / km / millimeters / milibars" class="SubContent"/>
<Image x:Name="Metric"
Grid.RowSpan="2"
Aspect="Center"
IsVisible="{Binding IsMetric}"
Source="checkmark_icon.png"
HorizontalOptions="End"
VerticalOptions="Center"/>
</Grid>
<BoxView class="HRule"/>

<Grid RowDefinitions="*,*">
<Grid RowDefinitions="30,30">
<Grid.GestureRecognizers>
<TapGestureRecognizer Command="{Binding SelectUnits}"
CommandParameter="hybrid"/>
Expand All @@ -92,25 +94,30 @@
Text="˚C / mph / miles / millimeters / millibars" class="SubContent"/>
<Image x:Name="Hybrid"
Grid.RowSpan="2"
Aspect="Center"
IsVisible="{Binding IsHybrid}"
Source="checkmark_icon.png"
HorizontalOptions="End"
VerticalOptions="Center"/>
</Grid>
<BoxView class="HRule"/>
<BoxView class="HRule"/>

<Label Text="More" class="SectionTitle"/>
<Label Text="More" class="SectionTitle"/>

<Grid RowDefinitions="*,*">
<Label Grid.Row="0"
Text="Support" class="Subhead"/>
<!-- <Label Grid.Row="1"
Text="˚C / mph / miles / millimeters / millibars" class="SubContent"/> -->
<Grid.GestureRecognizers>
<TapGestureRecognizer Tapped="OnSupportTapped"/>
</Grid.GestureRecognizers>
</Grid>
<BoxView class="HRule"/>
<Label Grid.Row="0"
Text="Support" class="Subhead">
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="OnSupportTapped"/>
</Label.GestureRecognizers>
</Label>


<BoxView class="HRule"/>

<FlexLayout HeightRequest="30" JustifyContent="SpaceBetween">
<Label Text="Dark Mode" class="Subhead"/>
<Switch IsToggled="{Binding IsDarkMode}" />
</FlexLayout>

</VerticalStackLayout>

Expand Down
32 changes: 16 additions & 16 deletions src/WeatherTwentyOne/Resources/Styles/DefaultTheme.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@
<!-- SHELL -->
<Style x:Key="BaseStyle"
TargetType="Element">
<Setter Property="Shell.FlyoutBackground"
Value="{StaticResource Background_Mid}"/>
<Setter Property="Shell.BackgroundColor"
Value="{StaticResource Background_Mid}" />
<Setter Property="Shell.ForegroundColor"
Value="{AppThemeBinding Light={StaticResource White}, Dark={StaticResource Black}}" />
<Setter Property="Shell.TitleColor"
Value="{AppThemeBinding Light={StaticResource White}, Dark={StaticResource Black}}" />
<Setter Property="Shell.DisabledColor"
Value="#B4000000" />
<Setter Property="Shell.UnselectedColor"
Value="#CC0000" />
<Setter Property="Shell.NavBarHasShadow"
Value="False"/>
</Style>
<Setter Property="Shell.FlyoutBackground"
Value="{AppThemeBinding Light={StaticResource NeutralDarker}, Dark={StaticResource Background_Mid}}"/>
<Setter Property="Shell.BackgroundColor"
Value="{AppThemeBinding Light={StaticResource NeutralDarker}, Dark={StaticResource Background_Mid}}" />
<Setter Property="Shell.ForegroundColor"
Value="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource White}}" />
<Setter Property="Shell.TitleColor"
Value="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource White}}" />
<Setter Property="Shell.DisabledColor"
Value="#B4000000" />
<Setter Property="Shell.UnselectedColor"
Value="#CC0000" />
<Setter Property="Shell.NavBarHasShadow"
Value="False"/>

</Style>

<Style BasedOn="{StaticResource BaseStyle}"
ApplyToDerivedTypes="True"
Expand Down
19 changes: 19 additions & 0 deletions src/WeatherTwentyOne/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ public string Units {
}
}

public bool IsDarkMode {
get {
return App.Current.UserAppTheme == OSAppTheme.Dark;
}
set {
App.Current.UserAppTheme = value ? OSAppTheme.Dark : OSAppTheme.Light;
OnPropertyChanged();
}
}

public string Temperature => IsImperial ? "70˚F" : "21˚C";

public bool IsImperial => units == "imperial";
Expand All @@ -29,9 +39,18 @@ public string Units {

public Command SelectUnits { get; set; }

public Command ChangeThemeMode { get; set; }

public SettingsViewModel()
{
SelectUnits = new Command<string>(OnSelectUnits);
ChangeThemeMode = new Command<bool>(OnChangeThemeMode);
}

private void OnChangeThemeMode(bool dark)
{
App.Current.UserAppTheme = dark ? OSAppTheme.Dark : OSAppTheme.Light;
OnPropertyChanged(nameof(IsDarkMode));
}

private void OnSelectUnits(string unit)
Expand Down

0 comments on commit 6c2849f

Please sign in to comment.