Skip to content

Commit

Permalink
Merge pull request #24 from Hikarisame-Technology/NotifyIcon
Browse files Browse the repository at this point in the history
Merge branch to C#
  • Loading branch information
Shizuku-Nanami authored Oct 18, 2024
2 parents 44a1692 + 0afc758 commit c75ab1d
Show file tree
Hide file tree
Showing 16 changed files with 232 additions and 163 deletions.
20 changes: 20 additions & 0 deletions SYSTools/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:muxc="http://schemas.inkore.net/lib/ui/wpf/modern"
xmlns:tb="http://www.hardcodet.net/taskbar"
xmlns:local="clr-namespace:SYSTools"
xmlns:model="clr-namespace:SYSTools.Model"
StartupUri="MainWindow.xaml"
ShutdownMode="OnExplicitShutdown"
>
<Application.Resources>
<ResourceDictionary>
Expand All @@ -13,6 +16,23 @@
</ResourceDictionary.MergedDictionaries>
<FontFamily x:Key="SegoeIcons">/SYSTools;component/Resources/#Segoe Fluent Icons</FontFamily>
<!-- Other app resources here -->
<!--托盘菜单-->
<ContextMenu x:Shared="false" x:Key="SysTrayMenu">
<MenuItem Header="显示窗口" Command="{Binding ShowWindowCommand}" />
<MenuItem Header="关闭窗口" Command="{Binding HideWindowCommand}" />
<Separator />
<MenuItem Header="退出" Command="{Binding ExitApplicationCommand}" />
</ContextMenu>
<tb:TaskbarIcon x:Key="Taskbar"
PopupActivation="DoubleClick"
DoubleClickCommand="{Binding ShowWindowCommand}"
ContextMenu="{StaticResource SysTrayMenu}"
IconSource="SYSTools_LOGO_256.ico">
<tb:TaskbarIcon.DataContext>
<model:NotifyIconViewModel/>
</tb:TaskbarIcon.DataContext>
</tb:TaskbarIcon>

</ResourceDictionary>
</Application.Resources>
</Application>
12 changes: 11 additions & 1 deletion SYSTools/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Hardcodet.Wpf.TaskbarNotification;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
Expand All @@ -13,5 +14,14 @@ namespace SYSTools
/// </summary>
public partial class App : Application
{
public static TaskbarIcon TaskbarIcon;

protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
TaskbarIcon = (TaskbarIcon)FindResource("Taskbar");
TaskbarIcon.ToolTipText = "SYSTools Ver" + (Application.ResourceAssembly.GetName().Version.ToString());

}
}
}
18 changes: 0 additions & 18 deletions SYSTools/Dialog/BackImageNew.xaml

This file was deleted.

29 changes: 0 additions & 29 deletions SYSTools/Dialog/BackImageNew.xaml.cs

This file was deleted.

19 changes: 0 additions & 19 deletions SYSTools/Dialog/BackImageOld.xaml

This file was deleted.

30 changes: 0 additions & 30 deletions SYSTools/Dialog/BackImageOld.xaml.cs

This file was deleted.

34 changes: 25 additions & 9 deletions SYSTools/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,34 @@
muxc:TitleBar.IsBackButtonVisible="False"
muxc:TitleBar.ButtonGlyphStyle="Fluent"
muxc:TitleBar.Height="48"
Height="670" Width="1100" MinWidth="1100" MinHeight="670" Loaded="Window_Loaded">

<Grid>
muxc:TitleBar.ExtendViewIntoTitleBar="True"
Loaded="Window_Loaded"
Closed="Window_Closed"
Deactivated="Window_Deactivated"
Height="670" Width="1100" MinWidth="1100" MinHeight="670" >

<Image x:Name="BackImage" Stretch="UniformToFill" Source="/Resources/Test2.jpg">
<Grid>
<!--设定为预设无背景图片-->
<Image x:Name="BackImage" Stretch="UniformToFill" Source="/Resources/NoBackImage.png">
<Image.Effect>
<BlurEffect/>
</Image.Effect>
</Image>

<Border x:Name="AppTitleBar" Grid.Column="1" VerticalAlignment="Top" Height="24" Margin="50,12,0,0">
<TextBlock x:Name="AppTitle" Text="" VerticalAlignment="Top" Margin="0,8,0,0"/>
</Border>

<Grid x:Name="AppTitleBar"
Height="48" HorizontalAlignment="Left" VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="LeftPaddingColumn" Width="0"/>
<ColumnDefinition/>
<ColumnDefinition x:Name="RightPaddingColumn" Width="0"/>
</Grid.ColumnDefinitions>
<TextBlock x:Name="TitleBarTextBlock"
FontWeight="Regular"
FontSize="12"
Grid.Column="1"
VerticalAlignment="Center"
Margin="16,0,0,0"/>
</Grid>

<muxc:NavigationView x:Name="Sidebar"
IsBackButtonVisible="Collapsed"
Expand All @@ -37,7 +52,8 @@
PaneDisplayMode="LeftCompact"
IsTabStop="False"
IsTitleBarAutoPaddingEnabled="True"
ItemInvoked="NavigationTriggered">
ItemInvoked="NavigationTriggered"
>
<FrameworkElement.Resources>
<SolidColorBrush x:Key="{x:Static muxc:ThemeKeys.NavigationViewContentBackgroundKey}" Color="Transparent"/>
<SolidColorBrush x:Key="{x:Static muxc:ThemeKeys.ExpanderHeaderBorderBrushKey}" Color="Transparent"/>
Expand Down
57 changes: 37 additions & 20 deletions SYSTools/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,6 @@ namespace SYSTools

public partial class MainWindow : Window
{
//private Frame Home_Page = new Frame() { Content = new Home() };
//private Frame FastDetection = new Frame() { Content = new Test() };
//private Frame DetectionTools = new Frame() { Content = new DetectionTools() };
//private Frame TestTools = new Frame() { Content = new TestTools() };
//private Frame DiskTools = new Frame() { Content = new DiskTools() };
//private Frame PeripheralsTools = new Frame() { Content = new PeripheralsTools() };
//private Frame RepairingTools = new Frame() { Content = new RepairingTools() };
//private Frame WindowsTools = new Frame() { Content = new WindowsTools() };
//private Frame WSATools = new Frame() { Content = new WSATools() };
//private Frame ConfigurationPage = new Frame() { Content = new Configuration() };
//private Frame AboutPage = new Frame() { Content = new About() };

private readonly Page Home_Page = new Home();
private readonly Page Test_Page = new Test();
private readonly Page DetectionTools_Page = new DetectionTools();
Expand All @@ -55,6 +43,7 @@ public MainWindow()
GlobalSettings.Instance.PropertyChanged += OnSettingsPropertyChanged;
}

// 监听全局设置修改
private void OnSettingsPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(GlobalSettings.BackgroundImagePath))
Expand All @@ -77,8 +66,9 @@ private void OnSettingsPropertyChanged(object sender, PropertyChangedEventArgs e

private void Window_Loaded(object sender, RoutedEventArgs e)
{
// 启动时删除Info.xml
File.Delete("Info.xml");
//程序启动数量限制
// 程序启动数量限制
string appName = Process.GetCurrentProcess().ProcessName;
int processTotal = Process.GetProcessesByName(appName).Length;
if (processTotal > 1)
Expand All @@ -90,8 +80,8 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
);
Close();
}
Title = "SYSTools Ver" + (Application.ResourceAssembly.GetName().Version.ToString());
//设置默认启动Page页
TitleBarTextBlock.Text = "SYSTools Ver" + (Application.ResourceAssembly.GetName().Version.ToString());
// 设置默认启动Page页
CurrentPage.Navigate(Home_Page, new DrillInNavigationTransitionInfo());
}

Expand All @@ -100,9 +90,7 @@ private void NavigationTriggered(
NavigationViewItemInvokedEventArgs args
)
{
if (args.IsSettingsInvoked)
NavigateTo(typeof(int), args.RecommendedNavigationTransitionInfo);
else if (args.InvokedItemContainer != null)
if (args.InvokedItemContainer != null)
NavigateTo(
Type.GetType(args.InvokedItemContainer.Tag.ToString()),
args.RecommendedNavigationTransitionInfo
Expand All @@ -111,6 +99,7 @@ NavigationViewItemInvokedEventArgs args

private void NavigateTo(Type navPageType, NavigationTransitionInfo transitionInfo)
{
// 导航到目标页
var preNavPageType = CurrentPage.Content.GetType();
if (navPageType == preNavPageType)
return;
Expand Down Expand Up @@ -154,11 +143,17 @@ private void NavigateTo(Type navPageType, NavigationTransitionInfo transitionInf

private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
if (!System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.PerUserRoamingAndLocal).HasFile)
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.Save();
LoadUserSettings();
// 加载用户配置
LoadUserSettings();
}

private void LoadUserSettings()
{
// 启动程序时加载 user.config 文件
string savedImagePath = Properties.Settings.Default.BackgroundImagePath;
double savedBlurRadius = Properties.Settings.Default.BackgroundImageBlurRadius;
if (!string.IsNullOrWhiteSpace(savedImagePath) && File.Exists(savedImagePath))
Expand All @@ -168,13 +163,15 @@ private void LoadUserSettings()
}
else
{
// 读取不到Config的背景图片路径或路径为空则设定为全透明图片路径
LoadBackgroundImage("pack://application:,,,/Resources/NoBackImage.png");
LoadBackgroundImageBlurRadius(savedBlurRadius);
}
}

private void LoadBackgroundImage(string imagePath)
{
// 加载背景图片
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.UriSource = new Uri(imagePath, UriKind.Absolute);
Expand All @@ -184,21 +181,41 @@ private void LoadBackgroundImage(string imagePath)

private void LoadBackgroundImageBlurRadius(double RadiusInt)
{
// 加载背景模糊
var blurEffect = new BlurEffect
{
Radius = RadiusInt // 获取模糊度
// 获取模糊度
Radius = RadiusInt
};
BackImage.Effect = blurEffect; // 应用模糊效果
// 为背景图片应用模糊效果
BackImage.Effect = blurEffect;
}

private void Dark_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
//实验性功能 设定为暗色模式
ThemeManager.Current.ApplicationTheme = ApplicationTheme.Dark;
}

private void Light_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
// 实验性功能 设定为亮色模式
ThemeManager.Current.ApplicationTheme = ApplicationTheme.Light;
}

private void Window_Closed(object sender, EventArgs e)
{
// 结束线程
Application.Current.Shutdown();
}

private void Window_Deactivated(object sender, EventArgs e)
{
// 修改最小化窗口为隐藏
if (WindowState == WindowState.Minimized)
{
Application.Current.MainWindow.Hide();
}
}
}
}
Loading

0 comments on commit c75ab1d

Please sign in to comment.