Skip to content

Commit

Permalink
Light theme modified, dark theme added and set as default one
Browse files Browse the repository at this point in the history
  • Loading branch information
enviGit committed Feb 21, 2023
1 parent 07a1dfd commit da0da9e
Show file tree
Hide file tree
Showing 8 changed files with 399 additions and 14 deletions.
2 changes: 1 addition & 1 deletion WeatherProphet/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
xmlns:local="clr-namespace:WeatherProphet"
StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>
</Application>
Binary file added WeatherProphet/Icons/dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WeatherProphet/Icons/light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 8 additions & 4 deletions WeatherProphet/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@
</ResourceDictionary>
</Window.Resources>
<Grid>
<Label Content="Weather Prophet" FontWeight="Bold" FontSize="24" VerticalAlignment="Top" HorizontalContentAlignment="Center" VerticalContentAlignment="Top" Background="#007ACC" Foreground="White"/>
<!--<Button Content="Toggle Theme" Click="Button_ToggleTheme" VerticalAlignment="Top" Margin="348,47,348,0"/>-->
<ComboBox Name="comboBoxDaysToShow" HorizontalAlignment="Left" Margin="293,114,0,0" VerticalAlignment="Top" Width="80" SelectedIndex="3">
<Label Content="Weather Prophet" FontWeight="Bold" FontSize="24" VerticalAlignment="Top" HorizontalContentAlignment="Center" VerticalContentAlignment="Top"/>
<Button Name="ToggleTheme" Click="Button_ToggleTheme" VerticalAlignment="Top" Margin="0,9,10,0" Style="{StaticResource ThemeButton}" Height="28" Width="67" HorizontalAlignment="Right">
<Button.Background>
<ImageBrush x:Name="ThemeImage" ImageSource="pack://application:,,,/Icons/dark.png"/>
</Button.Background>
</Button>
<TextBox Name="textBoxCity" HorizontalAlignment="Left" Margin="147,115,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120"/>
<ComboBox Name="comboBoxDaysToShow" HorizontalAlignment="Left" Margin="293,115,0,0" VerticalAlignment="Top" Width="80" SelectedIndex="3" Height="28">
<ComboBoxItem Content="1"/>
<ComboBoxItem Content="2"/>
<ComboBoxItem Content="3"/>
<ComboBoxItem Content="4"/>
</ComboBox>
<TextBox Name="textBoxCity" HorizontalAlignment="Left" Margin="147,115,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120"/>
<Button Content="Get Weather" HorizontalAlignment="Left" Margin="562,114,0,0" VerticalAlignment="Top" Width="76" Click="Button_Click"/>
<TextBlock Name="textBlockWeather" TextWrapping="Wrap" Text="" Margin="10,179,10,217"/>
<TextBlock Name="textBlockForecast" TextWrapping="Wrap" Text="" Margin="10,222,10,174"/>
Expand Down
6 changes: 6 additions & 0 deletions WeatherProphet/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;

#nullable disable

Expand Down Expand Up @@ -129,10 +130,15 @@ private async void Button_Click(object sender, RoutedEventArgs e)
private void Button_ToggleTheme(object sender, RoutedEventArgs e)
{
if (Resources.MergedDictionaries.Count > 0 && Resources.MergedDictionaries[0].Source.OriginalString == "Themes/DarkTheme.xaml")
{
Resources.MergedDictionaries.Clear();
ThemeImage.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Icons/light.png"));
Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri("Themes/LightTheme.xaml", UriKind.Relative) });
}
else
{
Resources.MergedDictionaries.Clear();
ThemeImage.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Icons/dark.png"));
Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri("Themes/DarkTheme.xaml", UriKind.Relative) });
}
}
Expand Down
192 changes: 183 additions & 9 deletions WeatherProphet/Themes/DarkTheme.xaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,189 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!--<Style TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="White"/>
<Setter Property="Background" Value="Black"/>
<LinearGradientBrush x:Key="BackgroundBrush" StartPoint="0,0" EndPoint="0,1">
<GradientStop Offset="0" Color="#2b2b2b"/>
<GradientStop Offset="1" Color="#242424"/>
</LinearGradientBrush>
<SolidColorBrush x:Key="ForegroundBrush" Color="#ffffff"/>
<SolidColorBrush x:Key="AccentBrush" Color="#ff8300"/>
<SolidColorBrush x:Key="AccentLightBrush" Color="#ffa632"/>
<SolidColorBrush x:Key="AccentDarkBrush" Color="#d55c00"/>

<Style TargetType="Grid">
<Setter Property="Background" Value="{StaticResource BackgroundBrush}"/>
</Style>
<Style TargetType="{x:Type Label}">
<Setter Property="Foreground" Value="White"/>
<Setter Property="Background" Value="Black"/>

<Style TargetType="Label">
<Setter Property="Background" Value="{StaticResource BackgroundBrush}"/>
<Setter Property="Foreground" Value="{StaticResource ForegroundBrush}"/>
<Setter Property="BorderBrush" Value="{StaticResource AccentBrush}"/>
<Setter Property="BorderThickness" Value="2"/>
</Style>

<ControlTemplate x:Key="ComboBoxToggleButton" TargetType="ToggleButton">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="20" />
</Grid.ColumnDefinitions>
<Border x:Name="Border"
Grid.ColumnSpan="2"
Background="{StaticResource BackgroundBrush}"
BorderBrush="{StaticResource AccentBrush}"
BorderThickness="1" />
<Border x:Name="InnerBorder"
Grid.Column="0"
Background="{StaticResource BackgroundBrush}"
Margin="1"
BorderBrush="{StaticResource AccentBrush}"
BorderThickness="0,0,1,0" />
<Path x:Name="Arrow"
Grid.Column="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Data="M 0 0 L 4 4 L 8 0 Z"
Fill="{StaticResource AccentBrush}" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Background" TargetName="Border" Value="{StaticResource AccentBrush}" />
<Setter Property="BorderBrush" TargetName="Border" Value="{StaticResource AccentBrush}" />
<Setter Property="Fill" TargetName="Arrow" Value="{StaticResource BackgroundBrush}" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" TargetName="Border" Value="{StaticResource AccentLightBrush}" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" Value="0.56" />
<Setter Property="Background" TargetName="Border" Value="{StaticResource BackgroundBrush}" />
<Setter Property="BorderBrush" TargetName="Border" Value="{StaticResource AccentBrush}" />
<Setter Property="Fill" TargetName="Arrow" Value="{StaticResource ForegroundBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>

<Style TargetType="ComboBox">
<Setter Property="Background" Value="{StaticResource BackgroundBrush}"/>
<Setter Property="Foreground" Value="{StaticResource ForegroundBrush}"/>
<Setter Property="BorderBrush" Value="{StaticResource AccentBrush}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Padding" Value="5"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBox">
<Grid>
<ToggleButton x:Name="ToggleButton"
Template="{StaticResource ComboBoxToggleButton}"
Grid.Column="2"
Focusable="false"
IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" />
<ContentPresenter x:Name="ContentSite"
IsHitTestVisible="False"
Content="{TemplateBinding SelectionBoxItem}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
Margin="3,3,23,3"
VerticalAlignment="Center"
HorizontalAlignment="Left" />
<Popup x:Name="Popup"
Placement="Bottom"
IsOpen="{TemplateBinding IsDropDownOpen}"
AllowsTransparency="True"
Focusable="False"
PopupAnimation="Slide">
<Grid x:Name="DropDown"
SnapsToDevicePixels="True"
MinWidth="{TemplateBinding ActualWidth}"
MaxHeight="{TemplateBinding MaxDropDownHeight}">
<Border x:Name="DropDownBorder"
Background="{StaticResource BackgroundBrush}"
BorderThickness="1"
BorderBrush="{StaticResource AccentBrush}" />
<ScrollViewer Margin="4,6,4,6" SnapsToDevicePixels="True">
<StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" />
</ScrollViewer>
</Grid>
</Popup>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True">
<Setter Property="BorderBrush" Value="{StaticResource AccentLightBrush}" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" TargetName="ContentSite" Value="0.56" />
</Trigger>
<DataTrigger Binding="{Binding Path=SelectedItem, RelativeSource={RelativeSource Self}}" Value="{x:Null}">
<Setter Property="Foreground" Value="{StaticResource ForegroundBrush}"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=SelectedItem, RelativeSource={RelativeSource Self}}" Value="{x:Null}">
<Setter Property="Background" Value="{StaticResource BackgroundBrush}"/>
</DataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Path=IsDropDownOpen, RelativeSource={RelativeSource Self}}" Value="True" />
<Condition Binding="{Binding Path=HasItems, RelativeSource={RelativeSource Self}}" Value="False" />
</MultiDataTrigger.Conditions>
<Setter Property="Visibility" TargetName="Popup" Value="Hidden" />
</MultiDataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<Style TargetType="TextBox">
<Setter Property="Background" Value="{StaticResource BackgroundBrush}"/>
<Setter Property="Foreground" Value="{StaticResource ForegroundBrush}"/>
<Setter Property="BorderBrush" Value="{StaticResource AccentBrush}"/>
<Setter Property="CaretBrush" Value="{StaticResource AccentLightBrush}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Padding" Value="5"/>
</Style>

<Style TargetType="Button">
<Setter Property="Background" Value="{StaticResource BackgroundBrush}"/>
<Setter Property="Foreground" Value="{StaticResource ForegroundBrush}"/>
<Setter Property="BorderBrush" Value="{StaticResource AccentBrush}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Padding" Value="5"/>
<Setter Property="Margin" Value="10"/>
<Setter Property="MinWidth" Value="100"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
</Style>
<Style TargetType="{x:Type Button}">

<Style x:Key="ThemeButton" TargetType="Button">
<Setter Property="Foreground" Value="White"/>
<Setter Property="Background" Value="Black"/>
</Style>-->
<Setter Property="Padding" Value="10"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<Style TargetType="TextBlock">
<Setter Property="Foreground" Value="{StaticResource ForegroundBrush}"/>
<Setter Property="Margin" Value="10"/>
</Style>

<Style TargetType="ListBox">
<Setter Property="Background" Value="{StaticResource BackgroundBrush}"/>
<Setter Property="Foreground" Value="{StaticResource ForegroundBrush}"/>
<Setter Property="BorderBrush" Value="{StaticResource AccentBrush}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Padding" Value="5"/>
<Setter Property="Margin" Value="10"/>
</Style>

<Style TargetType="ListBoxItem">
<Setter Property="Padding" Value="5"/>
</Style>

<Style TargetType="Image">
<Setter Property="Margin" Value="5"/>
</Style>
</ResourceDictionary>
Loading

0 comments on commit da0da9e

Please sign in to comment.