返回提交历史

XFEstudio/MyFirstRespo

完善主窗体的拖拽功能,以及自动化路径实现

b182290
X
xfe18827675401 <xfe18827675401@126.com>
提交于

代码差异

12 个文件 +258 -12
Added XFEToolBox.Core/Model/AppPath.cs +22 -0
@@ -0,0 +1,22 @@
1 using System.Reflection;
2 using XFEExtension.NetCore.AutoPath;
3
4 namespace XFEToolBox.Core.Model;
5
6 public partial class AppPath
7 {
8 [AutoPath]
9 private static readonly string appSynData = @$"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\XFEToolBox";
10 [AutoPath]
11 private static readonly string appLocalData = @$"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\XFEToolBox\CrossVersion";
12 [AutoPath]
13 private static readonly string appLocalVersionData = @$"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\XFEToolBox\Versions\{(Assembly.GetExecutingAssembly()?.GetName()?.Version?.ToString() ?? "UnknownVersion")}";
14 [AutoPath]
15 private static readonly string appCache = @$"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\Temp\XFEToolBox";
16 [AutoPath]
17 private static readonly string localProfile = @$"{AppLocalData}\Profiles";
18 [AutoPath]
19 private static readonly string localVersionProfile = $@"{AppLocalVersionData}\Profiles";
20 [AutoPath]
21 private static readonly string synProfile = $@"{AppSynData}\Profiles";
22 }
Added XFEToolBox.Core/XFEToolBox.Core.csproj +16 -0
@@ -0,0 +1,16 @@
1 <Project Sdk="Microsoft.NET.Sdk">
2
3 <PropertyGroup>
4 <TargetFramework>net8.0</TargetFramework>
5 <ImplicitUsings>enable</ImplicitUsings>
6 <Nullable>enable</Nullable>
7 </PropertyGroup>
8
9 <ItemGroup>
10 <PackageReference Include="XFEExtension.NetCore" Version="3.0.0" />
11 <PackageReference Include="XFEExtension.NetCore.AutoConfig" Version="1.0.4" />
12 <PackageReference Include="XFEExtension.NetCore.AutoPath" Version="1.0.1" />
13 <PackageReference Include="XFEExtension.NetCore.TodoHighLight" Version="1.0.0" />
14 </ItemGroup>
15
16 </Project>
Added XFEToolBox.Test/Program.cs +17 -0
@@ -0,0 +1,17 @@
1 using XFEToolBox.Core.Model;
2
3 namespace XFEToolBox.Test;
4
5 public class Program
6 {
7 [SMTest]
8 public static void PathTest()
9 {
10 Console.WriteLine($"""
11 应用同步文件夹:{AppPath.AppSynData}
12 应用本地文件夹:{AppPath.AppLocalData}
13 应用本地版本文件夹:{AppPath.AppLocalVersionData}
14 应用缓存文件夹:{AppPath.AppCache}
15 """);
16 }
17 }
Added XFEToolBox.Test/XFEToolBox.Test.csproj +20 -0
@@ -0,0 +1,20 @@
1 <Project Sdk="Microsoft.NET.Sdk">
2
3 <PropertyGroup>
4 <OutputType>Exe</OutputType>
5 <TargetFramework>net8.0</TargetFramework>
6 <ImplicitUsings>enable</ImplicitUsings>
7 <Nullable>enable</Nullable>
8 </PropertyGroup>
9
10 <ItemGroup>
11 <PackageReference Include="XFEExtension.NetCore" Version="3.0.0" />
12 <PackageReference Include="XFEExtension.NetCore.TodoHighLight" Version="1.0.0" />
13 <PackageReference Include="XFEExtension.NetCore.XUnit" Version="2.0.3" />
14 </ItemGroup>
15
16 <ItemGroup>
17 <ProjectReference Include="..\XFEToolBox.Core\XFEToolBox.Core.csproj" />
18 </ItemGroup>
19
20 </Project>
Modified XFEToolBox.sln +15 -0
@@ -5,6 +5,13 @@ VisualStudioVersion = 17.11.35017.193
5 5 MinimumVisualStudioVersion = 10.0.40219.1
6 6 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XFEToolBox", "XFEToolBox\XFEToolBox.csproj", "{7A065B44-8D37-4415-A97F-9F7C8F8E9567}"
7 7 EndProject
8 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XFEToolBox.Test", "XFEToolBox.Test\XFEToolBox.Test.csproj", "{9AEA29D2-6EC5-4CE2-BCC0-850160D81DBF}"
9 ProjectSection(ProjectDependencies) = postProject
10 {AA68EC1E-93C8-4D18-8372-64F3D91A66F1} = {AA68EC1E-93C8-4D18-8372-64F3D91A66F1}
11 EndProjectSection
12 EndProject
13 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XFEToolBox.Core", "XFEToolBox.Core\XFEToolBox.Core.csproj", "{AA68EC1E-93C8-4D18-8372-64F3D91A66F1}"
14 EndProject
8 15 Global
9 16 GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 17 Debug|Any CPU = Debug|Any CPU
@@ -15,6 +22,14 @@ Global
15 22 {7A065B44-8D37-4415-A97F-9F7C8F8E9567}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 23 {7A065B44-8D37-4415-A97F-9F7C8F8E9567}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 24 {7A065B44-8D37-4415-A97F-9F7C8F8E9567}.Release|Any CPU.Build.0 = Release|Any CPU
25 {9AEA29D2-6EC5-4CE2-BCC0-850160D81DBF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
26 {9AEA29D2-6EC5-4CE2-BCC0-850160D81DBF}.Debug|Any CPU.Build.0 = Debug|Any CPU
27 {9AEA29D2-6EC5-4CE2-BCC0-850160D81DBF}.Release|Any CPU.ActiveCfg = Release|Any CPU
28 {9AEA29D2-6EC5-4CE2-BCC0-850160D81DBF}.Release|Any CPU.Build.0 = Release|Any CPU
29 {AA68EC1E-93C8-4D18-8372-64F3D91A66F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
30 {AA68EC1E-93C8-4D18-8372-64F3D91A66F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
31 {AA68EC1E-93C8-4D18-8372-64F3D91A66F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
32 {AA68EC1E-93C8-4D18-8372-64F3D91A66F1}.Release|Any CPU.Build.0 = Release|Any CPU
18 33 EndGlobalSection
19 34 GlobalSection(SolutionProperties) = preSolution
20 35 HideSolutionNode = FALSE
Modified XFEToolBox/App.xaml.cs +10 -0
@@ -1,4 +1,7 @@
1 1 using System.Windows;
2 using XFEExtension.NetCore.AutoConfig;
3 using XFEToolBox.Core.Model;
4 using XFEToolBox.Profiles;
2 5
3 6 namespace XFEToolBox;
4 7
@@ -7,4 +10,11 @@ namespace XFEToolBox;
7 10 /// </summary>
8 11 public partial class App : Application
9 12 {
13 public App()
14 {
15 foreach (var profile in XFEProfile.Profiles)
16 {
17 //TODO:1 XFE各类拓展的AutoConfig需要改进
18 }
19 }
10 20 }
Added XFEToolBox/Profiles/SystemProfile.cs +9 -0
@@ -0,0 +1,9 @@
1 namespace XFEToolBox.Profiles;
2
3 public partial class SystemProfile
4 {
5 /// <summary>
6 /// 工具箱现在是否可以被关闭
7 /// </summary>
8 public static bool CanClosed { get; set; }
9 }
Modified XFEToolBox/Resources/Style/MainStyle.xaml +90 -7
@@ -1,16 +1,99 @@
1 1 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2 2 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
3 3 <Style x:Key="TabBorderStyle" TargetType="Border">
4 <Setter Property="Background" Value="#9898e7"/>
5 <Setter Property="HorizontalAlignment" Value="Stretch"/>
6 <Setter Property="VerticalAlignment" Value="Stretch"/>
4 7 <Style.Triggers>
5 <Trigger Property="IsMouseOver" Value="True">
6 <Trigger.Setters>
7 <Setter Property="Background" Value="#b4b4e9"/>
8 </Trigger.Setters>
9 </Trigger>
8 <EventTrigger RoutedEvent="MouseEnter">
9 <BeginStoryboard>
10 <Storyboard>
11 <ColorAnimation Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" To="#b4b4e9" Duration="0:0:0:0.1"/>
12 </Storyboard>
13 </BeginStoryboard>
14 </EventTrigger>
15 <EventTrigger RoutedEvent="MouseLeave">
16 <BeginStoryboard>
17 <Storyboard>
18 <ColorAnimation Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" To="#9898e7" Duration="0:0:0:0.1"/>
19 </Storyboard>
20 </BeginStoryboard>
21 </EventTrigger>
10 22 <EventTrigger RoutedEvent="MouseLeftButtonDown">
11 <BeginStoryboard Name="bgChange">
23 <BeginStoryboard>
24 <Storyboard>
25 <ColorAnimation Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" To="#ccccea" Duration="0:0:0:0.1"/>
26 </Storyboard>
27 </BeginStoryboard>
28 </EventTrigger>
29 <EventTrigger RoutedEvent="MouseLeftButtonUp">
30 <BeginStoryboard>
31 <Storyboard>
32 <ColorAnimation Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" To="#b4b4e9" Duration="0:0:0:0.1"/>
33 </Storyboard>
34 </BeginStoryboard>
35 </EventTrigger>
36 </Style.Triggers>
37 </Style>
38 <Style x:Key="HalfRotorImage" TargetType="Image">
39 <Setter Property="RenderTransformOrigin" Value="0.5,0.5"/>
40 <Setter Property="RenderTransform">
41 <Setter.Value>
42 <RotateTransform Angle="0"/>
43 </Setter.Value>
44 </Setter>
45 <Style.Triggers>
46 <EventTrigger RoutedEvent="MouseEnter">
47 <BeginStoryboard>
48 <Storyboard>
49 <DoubleAnimation Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" To="45" Duration="0:0:0.3">
50 <DoubleAnimation.EasingFunction>
51 <CubicEase EasingMode="EaseOut"/>
52 </DoubleAnimation.EasingFunction>
53 </DoubleAnimation>
54 </Storyboard>
55 </BeginStoryboard>
56 </EventTrigger>
57 <EventTrigger RoutedEvent="MouseLeave">
58 <BeginStoryboard>
59 <Storyboard>
60 <DoubleAnimation Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" To="0" Duration="0:0:0.3">
61 <DoubleAnimation.EasingFunction>
62 <CubicEase EasingMode="EaseOut"/>
63 </DoubleAnimation.EasingFunction>
64 </DoubleAnimation>
65 </Storyboard>
66 </BeginStoryboard>
67 </EventTrigger>
68 </Style.Triggers>
69 </Style>
70 <Style x:Key="RotorImage" TargetType="Image">
71 <Setter Property="RenderTransformOrigin" Value="0.5,0.5"/>
72 <Setter Property="RenderTransform">
73 <Setter.Value>
74 <RotateTransform Angle="0"/>
75 </Setter.Value>
76 </Setter>
77 <Style.Triggers>
78 <EventTrigger RoutedEvent="MouseEnter">
79 <BeginStoryboard>
80 <Storyboard>
81 <DoubleAnimation Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" To="90" Duration="0:0:0.3">
82 <DoubleAnimation.EasingFunction>
83 <CubicEase EasingMode="EaseOut"/>
84 </DoubleAnimation.EasingFunction>
85 </DoubleAnimation>
86 </Storyboard>
87 </BeginStoryboard>
88 </EventTrigger>
89 <EventTrigger RoutedEvent="MouseLeave">
90 <BeginStoryboard>
12 91 <Storyboard>
13 <ColorAnimation Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" To="White" Duration="0:0:0:0.1"/>
92 <DoubleAnimation Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" To="0" Duration="0:0:0.3">
93 <DoubleAnimation.EasingFunction>
94 <CubicEase EasingMode="EaseOut"/>
95 </DoubleAnimation.EasingFunction>
96 </DoubleAnimation>
14 97 </Storyboard>
15 98 </BeginStoryboard>
16 99 </EventTrigger>
Modified XFEToolBox/ViewModel/MainWindowViewModel.cs +33 -0
@@ -2,6 +2,8 @@
2 2 using XFEToolBox.Views.Pages;
3 3 using XFEToolBox.Views.Windows;
4 4 using System.Windows.Controls;
5 using System.Windows;
6 using XFEToolBox.Profiles;
5 7
6 8 namespace XFEToolBox.ViewModel;
7 9
@@ -16,4 +18,35 @@ public partial class MainWindowViewModel : ObservableObject
16 18 {
17 19 ViewPage = viewPage;
18 20 }
21 /// <summary>
22 /// 最小化窗体
23 /// </summary>
24 public void Minimize() => ViewPage!.WindowState = System.Windows.WindowState.Minimized;
25 /// <summary>
26 /// 关闭窗口退出应用
27 /// </summary>
28 /// <param name="forceExit">强制退出</param>
29 /// <returns>是否成功退出</returns>
30 public static bool ExitApp(bool forceExit)
31 {
32 if (forceExit || SystemProfile.CanClosed)
33 {
34 Application.Current.Shutdown();
35 return true;
36 }
37 else
38 {
39 return false;
40 }
41 }
42 public void CloseWindow()
43 {
44 ExitApp(true);
45 //TODO:1 待完善的退出应用逻辑,强制退出等
46 }
47
48 public void MoveWindow(int x, int y)
49 {
50
51 }
19 52 }
Modified XFEToolBox/Views/Windows/MainWindow.xaml +3 -3
@@ -27,11 +27,11 @@
27 27 <ColumnDefinition Width="45"/>
28 28 <ColumnDefinition Width="45"/>
29 29 </Grid.ColumnDefinitions>
30 <Border CornerRadius="0,0,20,20" Style="{StaticResource TabBorderStyle}">
30 <Border x:Name="dragTabBorder" CornerRadius="0,0,20,20" Style="{StaticResource TabBorderStyle}" MouseMove="DragTabBorder_MouseMove">
31 31 <Image x:Name="dragTabImage" Source="/Resources/Image/tabline.png" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="4"/>
32 32 </Border>
33 <Image x:Name="minimizeImage" x:FieldModifier="internal" Grid.Column="1" Source="/Resources/Image/min.png" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="4"/>
34 <Image x:Name="closeWindowImage" Grid.Column="2" Source="/Resources/Image/close.png" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="4"/>
33 <Image x:Name="minimizeImage" Style="{StaticResource RotorImage}" Grid.Column="1" Source="/Resources/Image/min.png" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="4" MouseLeftButtonUp="MinimizeImage_MouseLeftButtonUp"/>
34 <Image x:Name="closeWindowImage" Style="{StaticResource HalfRotorImage}" Grid.Column="2" Source="/Resources/Image/close.png" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="4" MouseLeftButtonUp="CloseWindowImage_MouseLeftButtonUp"/>
35 35 </Grid>
36 36 </Border>
37 37 <Border Grid.Column="0" Grid.Row="0" Background="Transparent">
Modified XFEToolBox/Views/Windows/MainWindow.xaml.cs +12 -2
@@ -1,5 +1,5 @@
1 using XFEToolBox.ViewModel;
2 using System.Windows;
1 using System.Windows;
2 using XFEToolBox.ViewModel;
3 3
4 4 namespace XFEToolBox.Views.Windows
5 5 {
@@ -17,5 +17,15 @@ namespace XFEToolBox.Views.Windows
17 17 DataContext = ViewModel;
18 18 Current = this;
19 19 }
20
21 private void MinimizeImage_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e) => ViewModel.Minimize();
22
23 private void CloseWindowImage_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e) => ViewModel.CloseWindow();
24
25 private void DragTabBorder_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
26 {
27 if (e.LeftButton == System.Windows.Input.MouseButtonState.Pressed)
28 DragMove();
29 }
20 30 }
21 31 }
Modified XFEToolBox/XFEToolBox.csproj +11 -0
@@ -16,6 +16,8 @@
16 16
17 17 <ItemGroup>
18 18 <PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
19 <PackageReference Include="EntityFramework" Version="5.0.0" />
20 <PackageReference Include="EntityFramework.zh-Hans" Version="5.0.0" />
19 21 <PackageReference Include="XFEExtension.NetCore" Version="3.0.0" />
20 22 <PackageReference Include="XFEExtension.NetCore.AutoConfig" Version="1.0.4" />
21 23 <PackageReference Include="XFEExtension.NetCore.AutoPath" Version="1.0.1" />
@@ -28,4 +30,13 @@
28 30 <Resource Include="Resources\Image\tabline.png" />
29 31 </ItemGroup>
30 32
33 <ItemGroup>
34 <Folder Include="Model\" />
35 <Folder Include="Views\Controls\" />
36 </ItemGroup>
37
38 <ItemGroup>
39 <ProjectReference Include="..\XFEToolBox.Core\XFEToolBox.Core.csproj" />
40 </ItemGroup>
41
31 42 </Project>