diff --git a/WinPowerHelper.Wpf/App.xaml b/WinPowerHelper.Wpf/App.xaml
index cdcf5c0..7981f7e 100644
--- a/WinPowerHelper.Wpf/App.xaml
+++ b/WinPowerHelper.Wpf/App.xaml
@@ -2,7 +2,8 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:viewmodels="clr-namespace:WinPowerHelper.Wpf.ViewModels"
- StartupUri="MainWindow.xaml">
+ StartupUri="MainWindow.xaml"
+ xmlns:system="clr-namespace:System;assembly=System.Runtime">
@@ -11,6 +12,8 @@
+ 32
+ 14
diff --git a/WinPowerHelper.Wpf/MainWindow.xaml b/WinPowerHelper.Wpf/MainWindow.xaml
index 2c4ce58..b8d75b9 100644
--- a/WinPowerHelper.Wpf/MainWindow.xaml
+++ b/WinPowerHelper.Wpf/MainWindow.xaml
@@ -8,26 +8,38 @@
xmlns:extensions="clr-namespace:WinPowerHelper.Wpf.Extensions"
mc:Ignorable="d"
DataContext="{StaticResource MainViewModel}"
- Title="{Binding AppTitle}"
- MinHeight="240" MinWidth="420" Width="500" Height="250"
- MaxHeight="400" MaxWidth="680" ResizeMode="CanMinimize">
+ Title="{Binding AppTitle}" WindowStyle="None"
+ MinHeight="240" MinWidth="420" Width="500" Height="200"
+ BorderThickness="1"
+ MaxHeight="400" MaxWidth="680" ResizeMode="CanMinimize" BorderBrush="{DynamicResource Brushes.Accent}">
+
-
-
+
+
+
-
+
+
+
+
+
-
-
\ No newline at end of file
diff --git a/WinPowerHelper.Wpf/Styles/Themes/Light.Blue.xaml b/WinPowerHelper.Wpf/Styles/Themes/Light.Blue.xaml
index 1b385ff..223315c 100644
--- a/WinPowerHelper.Wpf/Styles/Themes/Light.Blue.xaml
+++ b/WinPowerHelper.Wpf/Styles/Themes/Light.Blue.xaml
@@ -5,7 +5,7 @@
xmlns:system="clr-namespace:System;assembly=System.Runtime"
mc:Ignorable="options">
Light.Blue
- Blue (Light)
+ Blue (Light)
Light
Blue
diff --git a/WinPowerHelper.Wpf/Styles/Themes/Light.Pink.xaml b/WinPowerHelper.Wpf/Styles/Themes/Light.Pink.xaml
index 9c80db1..2a23309 100644
--- a/WinPowerHelper.Wpf/Styles/Themes/Light.Pink.xaml
+++ b/WinPowerHelper.Wpf/Styles/Themes/Light.Pink.xaml
@@ -6,7 +6,7 @@
mc:Ignorable="options">
Light.Pink
- Pink (Light)
+ Pink (Light)
Light
Pink
diff --git a/WinPowerHelper.Wpf/ThemeManager/Theme.cs b/WinPowerHelper.Wpf/ThemeManager/Theme.cs
index 70e39f9..1d6595d 100644
--- a/WinPowerHelper.Wpf/ThemeManager/Theme.cs
+++ b/WinPowerHelper.Wpf/ThemeManager/Theme.cs
@@ -21,7 +21,7 @@ public Theme(ResourceDictionary resources)
public const string ThemeNameKey = "Theme.Name";
public const string ThemeDisplayNameKey = "Theme.DisplayName";
public const string ThemeBaseColorSchemeKey = "Theme.BaseColorScheme";
- public const string ThemeColorSchemeKey = "Theme.ColorSchema";
+ public const string ThemeColorSchemeKey = "Theme.ColorScheme";
public const string ThemeShowcaseBrushKey = "Theme.ShowcaseBrush";
public string Name { get; set; }
diff --git a/WinPowerHelper.Wpf/ThemeManager/ThemeManager.cs b/WinPowerHelper.Wpf/ThemeManager/ThemeManager.cs
index d8d4006..61bf9ad 100644
--- a/WinPowerHelper.Wpf/ThemeManager/ThemeManager.cs
+++ b/WinPowerHelper.Wpf/ThemeManager/ThemeManager.cs
@@ -3,8 +3,8 @@
using System;
using System.Collections;
using System.Collections.Generic;
+ using System.Linq;
using System.Resources;
- using System.Text;
using System.Windows;
public static class ThemeManager
@@ -28,11 +28,18 @@ private set
}
}
+ ///
+ /// 确保 存在数据
+ ///
+ ///
+ /// 这个方法中不能调用属性 , 否则会造成 "循环引用"
+ /// 这个方法会被一直递归, 直到堆栈溢出
+ ///
private static void EnsureThemes()
{
- if (Themes.Count > 0) return;
+ if (_themes.Count > 0) return;
var assembly = typeof(ThemeManager).Assembly;
- var assemblyName = assembly.GetName();
+ var assemblyName = assembly.GetName().Name;
var resourceNames = assembly.GetManifestResourceNames();
foreach (var resourceName in resourceNames)
@@ -44,13 +51,47 @@ private static void EnsureThemes()
{
foreach (DictionaryEntry entry in reader)
{
- throw new NotImplementedException();
+ string stringKey = entry.Key as string;
+ if (stringKey == null ||
+ !stringKey.Contains("/themes/", StringComparison.OrdinalIgnoreCase) ||
+ !stringKey.EndsWith(".baml", StringComparison.OrdinalIgnoreCase) ||
+ stringKey.EndsWith("generic.baml", StringComparison.OrdinalIgnoreCase)) continue;
+
+ var resourceDictionary = new ResourceDictionary()
+ {
+ Source = new Uri(
+ $"pack://application:,,,/{assemblyName};component/{stringKey.Replace("baml", "xaml")}")
+ };
+
+ if (resourceDictionary != null &&
+ resourceDictionary.MergedDictionaries.Count == 0)
+ _themes.Add(new Theme(resourceDictionary));
+
}
}
-
-
}
}
+ public static void ChangeThemeColorScheme(ResourceDictionary resources, string newColorScheme)
+ {
+ var oldThemeResource = resources.MergedDictionaries.FirstOrDefault(
+ x => x.Source.LocalPath.Contains(
+ "light.", StringComparison.OrdinalIgnoreCase));
+
+ if (oldThemeResource[Theme.ThemeColorSchemeKey] as string == newColorScheme) return;
+
+ var newTheme = Themes.FirstOrDefault(x =>
+ x.ColorScheme.Equals(newColorScheme, StringComparison.OrdinalIgnoreCase));
+
+ string assemblyName = typeof(ThemeManager).Assembly.GetName().Name;
+ var newThemeResource = new ResourceDictionary
+ {
+ Source = new Uri(
+ $"pack://application:,,,/{assemblyName};component/Styles/Themes/Light.{newColorScheme}.xaml")
+ };
+ resources.MergedDictionaries.Add(newThemeResource);
+ if (oldThemeResource != null)
+ resources.MergedDictionaries.Remove(oldThemeResource);
+ }
}
}
diff --git a/WinPowerHelper.Wpf/ViewModels/MainViewModel.cs b/WinPowerHelper.Wpf/ViewModels/MainViewModel.cs
index 8663976..8636e6c 100644
--- a/WinPowerHelper.Wpf/ViewModels/MainViewModel.cs
+++ b/WinPowerHelper.Wpf/ViewModels/MainViewModel.cs
@@ -9,6 +9,9 @@
using WinPowerHelper.Core.Models;
using WinPowerHelper.Core.Services;
using WinPowerHelper.Wpf.Views;
+ using ThemeManager;
+ using System.Windows;
+ using System.Linq;
internal class MainViewModel : BindableBase
{
@@ -24,6 +27,11 @@ public MainViewModel()
Core.Models.PowerOptions.Shutdown,
Core.Models.PowerOptions.Restart,
};
+ Themes = ThemeManager.Themes;
+ SelectedTheme =
+ Themes.FirstOrDefault(
+ x => x.ColorScheme.Contains(
+ "blue", StringComparison.OrdinalIgnoreCase));
}
public static string AppTitle => "Windows定时关机助手";
@@ -35,9 +43,21 @@ public TimeSpan Interval
set => SetProperty(ref _interval, value);
}
+ public IList Themes { get; set; }
public List PowerOptions { get; set; }
public PowerOptions SelectedPowerOption { get; set; }
+ private Theme _selectedTheme;
+ public Theme SelectedTheme
+ {
+ get => _selectedTheme;
+ set
+ {
+ SetProperty(ref _selectedTheme, value);
+ ThemeManager.ChangeThemeColorScheme(Application.Current.Resources, value.ColorScheme);
+ }
+ }
+
public ICommand SetIntervalCmd { get; private set; }
public ICommand SetIntervalToZeroCmd { get; private set; }
public ICommand BeginOrStopTimingCmd { get; private set; }
diff --git a/WinPowerHelper.Wpf/Views/WindowTitleBar.xaml b/WinPowerHelper.Wpf/Views/WindowTitleBar.xaml
new file mode 100644
index 0000000..fad78d2
--- /dev/null
+++ b/WinPowerHelper.Wpf/Views/WindowTitleBar.xaml
@@ -0,0 +1,129 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/WinPowerHelper.Wpf/Views/WindowTitleBar.xaml.cs b/WinPowerHelper.Wpf/Views/WindowTitleBar.xaml.cs
new file mode 100644
index 0000000..6ce311b
--- /dev/null
+++ b/WinPowerHelper.Wpf/Views/WindowTitleBar.xaml.cs
@@ -0,0 +1,36 @@
+namespace WinPowerHelper.Wpf.Views
+{
+ using System.Windows.Controls;
+ using System.Windows.Input;
+ using System.Windows;
+
+ ///
+ /// Interaction logic for WindowTitleBar.xaml
+ ///
+ public partial class WindowTitleBar : UserControl
+ {
+ public WindowTitleBar()
+ {
+ InitializeComponent();
+
+ }
+
+ protected override void OnMouseMove(MouseEventArgs e)
+ {
+ base.OnMouseMove(e);
+ if (e.LeftButton == MouseButtonState.Pressed)
+ Application.Current.MainWindow.DragMove();
+ }
+
+
+ private void Minimize_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
+ {
+ Application.Current.MainWindow.WindowState = WindowState.Minimized;
+ }
+
+ private void Close_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
+ {
+ Application.Current.MainWindow.Close();
+ }
+ }
+}
diff --git a/WinPowerHelper.Wpf/Views/cb89p-4nv71-003.ico b/WinPowerHelper.Wpf/Views/cb89p-4nv71-003.ico
new file mode 100644
index 0000000..8dabfba
Binary files /dev/null and b/WinPowerHelper.Wpf/Views/cb89p-4nv71-003.ico differ
diff --git a/WinPowerHelper.Wpf/WinPowerHelper.Wpf.csproj b/WinPowerHelper.Wpf/WinPowerHelper.Wpf.csproj
index 247d9fc..51ad9da 100644
--- a/WinPowerHelper.Wpf/WinPowerHelper.Wpf.csproj
+++ b/WinPowerHelper.Wpf/WinPowerHelper.Wpf.csproj
@@ -17,6 +17,7 @@
+
@@ -29,6 +30,7 @@
+
\ No newline at end of file