U:调整右键菜单
This commit is contained in:
1 parent
ee5b83bb9d
commit
d76b1be28d
5 files changed
+222
-122
No files matched your search
@@ -1,5 +1,5 @@
|
||||
<Application
|
||||
x:Class="NetVizor.App"
|
||||
x:Class="Shell.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:NetVizor"
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Web;
|
||||
using System.Windows;
|
||||
using System.Windows.Threading;
|
||||
using Application;
|
||||
@@ -16,19 +10,13 @@ using Common.Net.HttpConn;
|
||||
using Common.Net.Models;
|
||||
using Common.Net.WebSocketConn;
|
||||
using Common.Utils;
|
||||
using Infrastructure.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog.Events;
|
||||
using Shell;
|
||||
using Shell.UserControls;
|
||||
using Shell.Utils;
|
||||
using Shell.Views;
|
||||
using Utils.ETW.Etw;
|
||||
using Utils.Firewall;
|
||||
using MessageBox = System.Windows.Forms.MessageBox;
|
||||
|
||||
namespace NetVizor;
|
||||
|
||||
using System.Windows.Forms; // 引用 Windows Forms 命名空间
|
||||
namespace Shell;
|
||||
// 引用 Windows Forms 命名空间
|
||||
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
@@ -528,4 +516,4 @@ public class SubscriptionAppInfo : SubscriptionInfo
|
||||
// 再有,“协议和端口”中的协议类型也有很多,我们也要展示。比如它甚至能指定用户,可以选择用户和组。
|
||||
// 所以基于上,我们几乎是重写了防火墙的页面。
|
||||
// 我现在需要你基于这个能获取到的信息(可能有些我没提到),使用html完成一个防火墙的看板,要点击某个规则可以编辑,可以新增。
|
||||
// 新增的窗口和交互都需要完成,数据的展示也需要完成。你用假数据替代数据填充即可,要求界面要现代化,美观,优雅
|
||||
// 新增的窗口和交互都需要完成,数据的展示也需要完成。你用假数据替代数据填充即可,要求界面要现代化,美观,优雅
|
||||
@@ -7,7 +7,7 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UseWPF>true</UseWPF>
|
||||
<UseWindowsForms>true</UseWindowsForms> <!-- 加上这句,才能正确启用 Forms 支持 -->
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
<!-- <ApplicationManifest>app.manifest</ApplicationManifest>-->
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,116 +1,189 @@
|
||||
<Window x:Class="Shell.UserControls.TrayMenuWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Shell.UserControls"
|
||||
mc:Ignorable="d"
|
||||
Title="TrayMenu"
|
||||
Height="200" Width="180"
|
||||
WindowStyle="None"
|
||||
AllowsTransparency="True"
|
||||
Background="Transparent"
|
||||
Topmost="True"
|
||||
ShowInTaskbar="False"
|
||||
ResizeMode="NoResize"
|
||||
Deactivated="Window_Deactivated">
|
||||
|
||||
<Window
|
||||
x:Class="Shell.UserControls.TrayMenuWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Shell.UserControls"
|
||||
mc:Ignorable="d"
|
||||
Title="TrayMenu"
|
||||
Height="180"
|
||||
Width="150"
|
||||
Topmost="True"
|
||||
ShowInTaskbar="False"
|
||||
ResizeMode="NoResize"
|
||||
Deactivated="Window_Deactivated"
|
||||
WindowStyle="None"
|
||||
AllowsTransparency="True"
|
||||
Background="Transparent"
|
||||
Loaded="Window_Loaded">
|
||||
<Window.Resources>
|
||||
<!-- 菜单项样式 -->
|
||||
<Style x:Key="MenuItemStyle" TargetType="Border">
|
||||
<Setter Property="Padding" Value="15,8" />
|
||||
<Setter Property="Cursor" Value="Hand" />
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<!-- 更柔和的菜单项样式 -->
|
||||
<Style
|
||||
x:Key="MenuItemStyle"
|
||||
TargetType="Border">
|
||||
<Setter
|
||||
Property="Padding"
|
||||
Value="8,8" />
|
||||
<Setter
|
||||
Property="Cursor"
|
||||
Value="Hand" />
|
||||
<Setter
|
||||
Property="Background"
|
||||
Value="Transparent" />
|
||||
<Setter
|
||||
Property="CornerRadius"
|
||||
Value="6" />
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Background" Value="#E3F2FD" />
|
||||
<Trigger
|
||||
Property="IsMouseOver"
|
||||
Value="True">
|
||||
<Setter
|
||||
Property="Background"
|
||||
Value="#F0F0F0" />
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
<!-- 图标样式 -->
|
||||
<Style x:Key="IconStyle" TargetType="TextBlock">
|
||||
<Setter Property="FontFamily" Value="Segoe MDL2 Assets" />
|
||||
<Setter Property="FontSize" Value="16" />
|
||||
<Setter Property="Foreground" Value="#2196F3" />
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
<Setter Property="Margin" Value="0,0,10,0" />
|
||||
<!-- 图标 -->
|
||||
<Style
|
||||
x:Key="IconStyle"
|
||||
TargetType="TextBlock">
|
||||
<Setter
|
||||
Property="FontFamily"
|
||||
Value="Segoe Fluent Icons" />
|
||||
<Setter
|
||||
Property="FontSize"
|
||||
Value="16" />
|
||||
<Setter
|
||||
Property="Foreground"
|
||||
Value="#0063B1" />
|
||||
<Setter
|
||||
Property="VerticalAlignment"
|
||||
Value="Center" />
|
||||
<Setter
|
||||
Property="Margin"
|
||||
Value="0,0,8,0" />
|
||||
</Style>
|
||||
|
||||
<!-- 文本样式 -->
|
||||
<Style x:Key="TextStyle" TargetType="TextBlock">
|
||||
<Setter Property="FontSize" Value="13" />
|
||||
<Setter Property="Foreground" Value="#333333" />
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
<!-- 文本 -->
|
||||
<Style
|
||||
x:Key="TextStyle"
|
||||
TargetType="TextBlock">
|
||||
<Setter
|
||||
Property="FontSize"
|
||||
Value="14" />
|
||||
<Setter
|
||||
Property="Foreground"
|
||||
Value="#1F1F1F" />
|
||||
<Setter
|
||||
Property="FontWeight"
|
||||
Value="SemiBold" />
|
||||
<Setter
|
||||
Property="VerticalAlignment"
|
||||
Value="Center" />
|
||||
</Style>
|
||||
|
||||
<!-- 分隔线样式 -->
|
||||
<Style x:Key="SeparatorStyle" TargetType="Rectangle">
|
||||
<Setter Property="Height" Value="1" />
|
||||
<Setter Property="Fill" Value="#E0E0E0" />
|
||||
<Setter Property="Margin" Value="10,5" />
|
||||
<!-- 分隔线 -->
|
||||
<Style
|
||||
x:Key="SeparatorStyle"
|
||||
TargetType="Rectangle">
|
||||
<Setter
|
||||
Property="Height"
|
||||
Value="1" />
|
||||
<Setter
|
||||
Property="Fill"
|
||||
Value="#DDDDDD" />
|
||||
<Setter
|
||||
Property="Margin"
|
||||
Value="8,6" />
|
||||
</Style>
|
||||
</Window.Resources>
|
||||
|
||||
<Border Background="White"
|
||||
CornerRadius="8"
|
||||
BorderBrush="#E0E0E0"
|
||||
BorderThickness="1">
|
||||
<Border.Effect>
|
||||
<DropShadowEffect ShadowDepth="3"
|
||||
Direction="315"
|
||||
Color="#40000000"
|
||||
Opacity="0.3"
|
||||
BlurRadius="10" />
|
||||
</Border.Effect>
|
||||
<Grid>
|
||||
<Border
|
||||
CornerRadius="10"
|
||||
Background="#FFF"
|
||||
BorderBrush="#DDDDDD"
|
||||
BorderThickness="1"
|
||||
Padding="3">
|
||||
<Border.Effect>
|
||||
<DropShadowEffect
|
||||
ShadowDepth="3"
|
||||
Direction="315"
|
||||
Color="#33000000"
|
||||
Opacity="0.25"
|
||||
BlurRadius="12" />
|
||||
</Border.Effect>
|
||||
|
||||
<StackPanel Margin="5">
|
||||
<!-- 打开主窗口 -->
|
||||
<Border Style="{StaticResource MenuItemStyle}"
|
||||
<StackPanel
|
||||
Margin="6">
|
||||
<!-- 示例:你也可以替换图标字符 -->
|
||||
<Border
|
||||
Style="{StaticResource MenuItemStyle}"
|
||||
MouseLeftButtonDown="ShowMainWindow_Click">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="" Style="{StaticResource IconStyle}" />
|
||||
<TextBlock Text="打开主窗口" Style="{StaticResource TextStyle}" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
<StackPanel
|
||||
Orientation="Horizontal">
|
||||
<TextBlock
|
||||
Text=""
|
||||
Style="{StaticResource IconStyle}" />
|
||||
<TextBlock
|
||||
Text="打开主窗口"
|
||||
Style="{StaticResource TextStyle}" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<!-- 分隔线 -->
|
||||
<Rectangle Style="{StaticResource SeparatorStyle}" />
|
||||
<Rectangle
|
||||
Style="{StaticResource SeparatorStyle}" />
|
||||
|
||||
<!-- 最小化到托盘 -->
|
||||
<Border Style="{StaticResource MenuItemStyle}"
|
||||
<Border
|
||||
Style="{StaticResource MenuItemStyle}"
|
||||
MouseLeftButtonDown="HideToTray_Click">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="" Style="{StaticResource IconStyle}" />
|
||||
<TextBlock Text="最小化到托盘" Style="{StaticResource TextStyle}" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
<StackPanel
|
||||
Orientation="Horizontal">
|
||||
<TextBlock
|
||||
Text=""
|
||||
Style="{StaticResource IconStyle}" />
|
||||
<TextBlock
|
||||
Text="最小化到托盘"
|
||||
Style="{StaticResource TextStyle}" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<!-- 关于 -->
|
||||
<Border Style="{StaticResource MenuItemStyle}"
|
||||
<Border
|
||||
Style="{StaticResource MenuItemStyle}"
|
||||
MouseLeftButtonDown="About_Click">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="" Style="{StaticResource IconStyle}" />
|
||||
<TextBlock Text="关于" Style="{StaticResource TextStyle}" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
<StackPanel
|
||||
Orientation="Horizontal">
|
||||
<TextBlock
|
||||
Text=""
|
||||
Style="{StaticResource IconStyle}" />
|
||||
<TextBlock
|
||||
Text="关于"
|
||||
Style="{StaticResource TextStyle}" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<!-- 分隔线 -->
|
||||
<Rectangle Style="{StaticResource SeparatorStyle}" />
|
||||
<Rectangle
|
||||
Style="{StaticResource SeparatorStyle}" />
|
||||
|
||||
<!-- 退出程序 -->
|
||||
<Border Style="{StaticResource MenuItemStyle}"
|
||||
<Border
|
||||
Style="{StaticResource MenuItemStyle}"
|
||||
MouseLeftButtonDown="ExitApplication_Click">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text=""
|
||||
Style="{StaticResource IconStyle}"
|
||||
Foreground="#F44336" />
|
||||
<TextBlock Text="退出程序"
|
||||
Style="{StaticResource TextStyle}"
|
||||
Foreground="#F44336" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
<StackPanel
|
||||
Orientation="Horizontal">
|
||||
<TextBlock
|
||||
Text=""
|
||||
Style="{StaticResource IconStyle}"
|
||||
Foreground="#D32F2F" />
|
||||
<TextBlock
|
||||
Text="退出程序"
|
||||
Style="{StaticResource TextStyle}"
|
||||
Foreground="#D32F2F" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
|
||||
</Window>
|
||||
</Window>
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media.Animation;
|
||||
@@ -13,8 +14,28 @@ public partial class TrayMenuWindow : Window
|
||||
public event Action OnHideToTray;
|
||||
|
||||
// 菜单的固定尺寸(与XAML中设置的一致)
|
||||
private const double MENU_WIDTH = 180;
|
||||
private const double MENU_HEIGHT = 200;
|
||||
private const double MENU_WIDTH = 150;
|
||||
private const double MENU_HEIGHT = 180;
|
||||
|
||||
[DllImport("dwmapi.dll")]
|
||||
private static extern int DwmEnableBlurBehindWindow(IntPtr hwnd, ref DWM_BLURBEHIND blurBehind);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private struct DWM_BLURBEHIND
|
||||
{
|
||||
public DWM_BB dwFlags;
|
||||
public bool fEnable;
|
||||
public IntPtr hRgnBlur;
|
||||
public bool fTransitionOnMaximized;
|
||||
}
|
||||
|
||||
[Flags]
|
||||
private enum DWM_BB : uint
|
||||
{
|
||||
Enable = 0x00000001,
|
||||
BlurRegion = 0x00000002,
|
||||
TransitionMaximized = 0x00000004
|
||||
}
|
||||
|
||||
public TrayMenuWindow()
|
||||
{
|
||||
@@ -33,6 +54,24 @@ public partial class TrayMenuWindow : Window
|
||||
};
|
||||
}
|
||||
|
||||
private void Window_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
EnableBlur();
|
||||
}
|
||||
|
||||
private void EnableBlur()
|
||||
{
|
||||
var windowHelper = new WindowInteropHelper(this);
|
||||
var blur = new DWM_BLURBEHIND
|
||||
{
|
||||
fEnable = true,
|
||||
dwFlags = DWM_BB.Enable,
|
||||
hRgnBlur = IntPtr.Zero,
|
||||
fTransitionOnMaximized = false
|
||||
};
|
||||
DwmEnableBlurBehindWindow(windowHelper.Handle, ref blur);
|
||||
}
|
||||
|
||||
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
|
||||
{
|
||||
// 处理DPI变化消息
|
||||
@@ -49,22 +88,22 @@ public partial class TrayMenuWindow : Window
|
||||
private void TrayMenuWindow_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// 添加淡入动画
|
||||
// var fadeIn = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(200));
|
||||
// this.BeginAnimation(OpacityProperty, fadeIn);
|
||||
var fadeIn = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(200));
|
||||
this.BeginAnimation(OpacityProperty, fadeIn);
|
||||
|
||||
// 添加缩放动画
|
||||
// var scaleTransform = new System.Windows.Media.ScaleTransform(0.8, 0.8);
|
||||
var scaleTransform = new System.Windows.Media.ScaleTransform(0.8, 0.8);
|
||||
// this.RenderTransform = scaleTransform;
|
||||
// this.RenderTransformOrigin = new System.Windows.Point(0.5, 0.5);
|
||||
|
||||
// var scaleXAnimation = new DoubleAnimation(0.8, 1, TimeSpan.FromMilliseconds(200));
|
||||
// var scaleYAnimation = new DoubleAnimation(0.8, 1, TimeSpan.FromMilliseconds(200));
|
||||
var scaleXAnimation = new DoubleAnimation(0.8, 1, TimeSpan.FromMilliseconds(200));
|
||||
var scaleYAnimation = new DoubleAnimation(0.8, 1, TimeSpan.FromMilliseconds(200));
|
||||
|
||||
// scaleXAnimation.EasingFunction = new QuadraticEase();
|
||||
// scaleYAnimation.EasingFunction = new QuadraticEase();
|
||||
scaleXAnimation.EasingFunction = new QuadraticEase();
|
||||
scaleYAnimation.EasingFunction = new QuadraticEase();
|
||||
|
||||
// scaleTransform.BeginAnimation(System.Windows.Media.ScaleTransform.ScaleXProperty, scaleXAnimation);
|
||||
// scaleTransform.BeginAnimation(System.Windows.Media.ScaleTransform.ScaleYProperty, scaleYAnimation);
|
||||
scaleTransform.BeginAnimation(System.Windows.Media.ScaleTransform.ScaleXProperty, scaleXAnimation);
|
||||
scaleTransform.BeginAnimation(System.Windows.Media.ScaleTransform.ScaleYProperty, scaleYAnimation);
|
||||
}
|
||||
|
||||
public void ShowAt(int x, int y)
|
||||
@@ -253,4 +292,4 @@ public partial class TrayMenuWindow : Window
|
||||
// 当窗口失去焦点时自动隐藏
|
||||
this.Hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user