返回提交历史

XFEstudio/MyFirstRespo

完善设置界面

d28e063
X
XFEstudio <mail@xfegzs.com>
提交于

代码差异

20 个文件 +716 -44
Modified XFEToolBox/App.xaml.cs +0 -1
@@ -11,7 +11,6 @@ public partial class App : Application
11 11 public App()
12 12 {
13 13 this.InitializeComponent();
14 //XFEConsole.UseXFEConsole().Wait();
15 14 }
16 15 protected override void OnStartup(StartupEventArgs e)
17 16 {
Modified XFEToolBox/Profiles/CrossVersionProfiles/ConsoleProfile.cs +1 -1
@@ -24,6 +24,6 @@ public partial class ConsoleProfile
24 24 /// 最大行数
25 25 /// </summary>
26 26 [ProfileProperty]
27 private int maxLine = 9999;
27 private int maxLine = 8000;
28 28 public ConsoleProfile() => ProfilePath = @$"{AppPath.LocalProfile}\{typeof(ConsoleProfile)}.xprofile";
29 29 }
Added XFEToolBox/Profiles/CrossVersionProfiles/DownloadProfile.cs +24 -0
@@ -0,0 +1,24 @@
1 using XFEExtension.NetCore.AutoConfig;
2 using XFEToolBox.Core.Model;
3
4 namespace XFEToolBox.Profiles.CrossVersionProfiles;
5
6 public partial class DownloadProfile
7 {
8 /// <summary>
9 /// 是否使用一般的下载方式
10 /// </summary>
11 [ProfileProperty]
12 private bool useNormalDownloader = false;
13 /// <summary>
14 /// 下载的目标文件夹
15 /// </summary>
16 [ProfileProperty]
17 private string downloadDirectory = $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}\\Downloads";
18 /// <summary>
19 /// 加速下载的线程数
20 /// </summary>
21 [ProfileProperty]
22 private int downloadThread = 9;
23 public DownloadProfile() => ProfilePath = @$"{AppPath.LocalProfile}\{typeof(DownloadProfile)}.xprofile";
24 }
Added XFEToolBox/Resources/Image/invisible.png +0 -0
二进制文件已变更,无法进行逐行预览。
Added XFEToolBox/Resources/Image/visible.png +0 -0
二进制文件已变更,无法进行逐行预览。
Modified XFEToolBox/Resources/Style/MainStyle.xaml +1 -2
@@ -195,8 +195,7 @@
195 195 <Setter.Value>
196 196 <ControlTemplate TargetType="Button">
197 197 <Grid x:Name="grid">
198 <Border x:Name="border" CornerRadius="5" Background="White" Opacity="0.1">
199 </Border>
198 <Border x:Name="border" CornerRadius="5" Background="White" Opacity="0.1"/>
200 199 <ContentPresenter Margin="5,3"/>
201 200 </Grid>
202 201 <ControlTemplate.Triggers>
Modified XFEToolBox/Resources/Style/MyControlsStyle.xaml +22 -5
@@ -2,10 +2,11 @@
2 2 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3 3 xmlns:ctr="clr-namespace:XFEToolBox.Views.Controls">
4 4 <Style TargetType="{x:Type ctr:RoundButton}">
5 <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
5 6 <Setter Property="Template">
6 7 <Setter.Value>
7 8 <ControlTemplate TargetType="{x:Type ctr:RoundButton}">
8 <Grid x:Name="grid">
9 <Grid>
9 10 <Border x:Name="backBorder" CornerRadius="{TemplateBinding RoundCornerRadius}" Background="{TemplateBinding RoundButtonBackground}" Opacity="0"/>
10 11 <Border CornerRadius="{TemplateBinding RoundCornerRadius}" BorderBrush="{TemplateBinding RoundButtonBorderBrush}" BorderThickness="{TemplateBinding RoundButtonBorderThickness}">
11 12 <ContentPresenter Content="{TemplateBinding Content}"/>
@@ -346,17 +347,33 @@
346 347 <Setter Property="Template">
347 348 <Setter.Value>
348 349 <ControlTemplate TargetType="{x:Type ctr:HintTextBox}">
349
350 <TextBox x:Name="mainTextBox" BorderThickness="{TemplateBinding BorderThickness}" Text="{Binding Text, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Foreground="{TemplateBinding Foreground}" CaretBrush="{TemplateBinding CaretBrush}" SelectionBrush="{TemplateBinding SelectionBrush}" SelectionTextBrush="{TemplateBinding SelectionTextBrush}" IsReadOnly="{TemplateBinding IsReadOnly}" IsReadOnlyCaretVisible="{TemplateBinding IsReadOnlyCaretVisible}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" HorizontalScrollBarVisibility="{TemplateBinding HorizontalScrollBarVisibility}" VerticalScrollBarVisibility="{TemplateBinding VerticalScrollBarVisibility}" AcceptsReturn="{TemplateBinding AcceptsReturn}" AcceptsTab="{TemplateBinding AcceptsTab}" IsEnabled="{TemplateBinding IsEnabled}" IsInactiveSelectionHighlightEnabled="{TemplateBinding IsInactiveSelectionHighlightEnabled}" UndoLimit="{TemplateBinding UndoLimit}" IsUndoEnabled="{TemplateBinding IsUndoEnabled}" TextWrapping="{TemplateBinding TextWrapping}" TextAlignment="{TemplateBinding TextAlignment}" TextDecorations="{TemplateBinding TextDecorations}">
351 <TextBox.Background>
352 <VisualBrush TileMode="None" Stretch="None" AlignmentX="Left">
353 <VisualBrush.Visual>
354 <TextBlock x:Name="hintTextBlock" Background="{TemplateBinding HintBackground}" Foreground="{TemplateBinding HintForeground}" Text="{TemplateBinding HintText}" FontSize="{TemplateBinding HintFontSize}" FontFamily="{TemplateBinding HintFontFamily}" FontWeight="{TemplateBinding HintFontWeight}" HorizontalAlignment="{TemplateBinding HintTextHorizontalAlignment}" VerticalAlignment="{TemplateBinding HintTextVerticalAlignment}" Margin="{TemplateBinding HintTextMargin}" Opacity="{TemplateBinding HintTextOpacity}" Visibility="Hidden"/>
355 </VisualBrush.Visual>
356 </VisualBrush>
357 </TextBox.Background>
358 </TextBox>
359 <ControlTemplate.Triggers>
360 <Trigger SourceName="mainTextBox" Property="Text" Value="">
361 <Setter TargetName="hintTextBlock" Property="Visibility" Value="Visible"/>
362 </Trigger>
363 <Trigger SourceName="mainTextBox" Property="Text" Value="{x:Null}">
364 <Setter TargetName="hintTextBlock" Property="Visibility" Value="Visible"/>
365 </Trigger>
366 </ControlTemplate.Triggers>
350 367 </ControlTemplate>
351 368 </Setter.Value>
352 369 </Setter>
353 370 </Style>
354 <Style x:Key="TextEditor" TargetType="{x:Type ctr:TextEditor}">
371 <Style TargetType="{x:Type ctr:TextEditor}">
355 372 <Setter Property="Template">
356 373 <Setter.Value>
357 374 <ControlTemplate TargetType="{x:Type ctr:TextEditor}">
358 <Border Padding="{TemplateBinding Padding}" CornerRadius="{TemplateBinding EditorCornerRadius}" BorderBrush="{TemplateBinding EditorBorderBrush}" BorderThickness="{TemplateBinding EditorBorderThickness}">
359 <ctr:HintTextBox BorderThickness="0" Background="{TemplateBinding Background}" Foreground="{TemplateBinding Foreground}" HintBackground="{TemplateBinding HintBackground}" HintForeground="{TemplateBinding HintForeground}" HintText="{TemplateBinding HintText}" HintFontSize="{TemplateBinding HintFontSize}" HintFontFamily="{TemplateBinding HintFontFamily}" HintFontWeight="{TemplateBinding HintFontWeight}" HintTextHorizontalAlignment="{TemplateBinding HintTextHorizontalAlignment}" HintTextVerticalAlignment="{TemplateBinding HintTextVerticalAlignment}" HintTextMargin="{TemplateBinding HintTextMargin}" HintTextOpacity="{TemplateBinding HintTextOpacity}"/>
375 <Border Padding="{TemplateBinding Padding}" CornerRadius="{TemplateBinding EditorCornerRadius}" BorderBrush="{TemplateBinding EditorBorderBrush}" BorderThickness="{TemplateBinding EditorBorderThickness}" Background="{TemplateBinding Background}">
376 <ctr:HintTextBox BorderThickness="0" Background="{TemplateBinding Background}" Foreground="{TemplateBinding Foreground}" HintBackground="{TemplateBinding HintBackground}" Text="{Binding Text, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" HintForeground="{TemplateBinding HintForeground}" HintText="{TemplateBinding HintText}" HintFontSize="{TemplateBinding HintFontSize}" HintFontFamily="{TemplateBinding HintFontFamily}" HintFontWeight="{TemplateBinding HintFontWeight}" HintTextHorizontalAlignment="{TemplateBinding HintTextHorizontalAlignment}" HintTextVerticalAlignment="{TemplateBinding HintTextVerticalAlignment}" HintTextMargin="{TemplateBinding HintTextMargin}" HintTextOpacity="{TemplateBinding HintTextOpacity}" CaretBrush="{TemplateBinding CaretBrush}" SelectionBrush="{TemplateBinding SelectionBrush}" SelectionTextBrush="{TemplateBinding SelectionTextBrush}" IsReadOnly="{TemplateBinding IsReadOnly}" IsReadOnlyCaretVisible="{TemplateBinding IsReadOnlyCaretVisible}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" HorizontalScrollBarVisibility="{TemplateBinding HorizontalScrollBarVisibility}" VerticalScrollBarVisibility="{TemplateBinding VerticalScrollBarVisibility}" AcceptsReturn="{TemplateBinding AcceptsReturn}" AcceptsTab="{TemplateBinding AcceptsTab}" IsEnabled="{TemplateBinding IsEnabled}" IsInactiveSelectionHighlightEnabled="{TemplateBinding IsInactiveSelectionHighlightEnabled}" UndoLimit="{TemplateBinding UndoLimit}" IsUndoEnabled="{TemplateBinding IsUndoEnabled}" TextWrapping="{TemplateBinding TextWrapping}" TextAlignment="{TemplateBinding TextAlignment}" TextDecorations="{TemplateBinding TextDecorations}"/>
360 377 </Border>
361 378 </ControlTemplate>
362 379 </Setter.Value>
Modified XFEToolBox/ViewModel/SettingPageViewModel.cs +143 -3
@@ -1,10 +1,14 @@
1 1 using CommunityToolkit.Mvvm.ComponentModel;
2 2 using CommunityToolkit.Mvvm.Input;
3 using Microsoft.Win32;
4 using System.Diagnostics;
3 5 using System.IO;
4 6 using System.Windows;
7 using System.Windows.Controls;
5 8 using System.Windows.Media;
6 9 using XFEExtension.NetCore.FileExtension;
7 10 using XFEToolBox.Core.Model;
11 using XFEToolBox.Profiles.CrossVersionProfiles;
8 12 using XFEToolBox.Utilities;
9 13 using XFEToolBox.Views.Controls;
10 14 using XFEToolBox.Views.Pages;
@@ -23,6 +27,8 @@ public partial class SettingPageViewModel(SettingPage viewPage) : ObservableObje
23 27 string synchronizeProfileSize = "计算中...";
24 28 [ObservableProperty]
25 29 string totalProfileSize = "计算中...";
30 [ObservableProperty]
31 string downloadDirectory = "目标下载目录:";
26 32 public SettingPage ViewPage { get; set; } = viewPage;
27 33
28 34 public static void LoadSettingProfile(DependencyObject parent)
@@ -33,11 +39,117 @@ public partial class SettingPageViewModel(SettingPage viewPage) : ObservableObje
33 39 for (int i = 0; i < childrenCount; i++)
34 40 {
35 41 var child = VisualTreeHelper.GetChild(parent, i);
36 if (child is SwitchButton switchButton && switchButton.Tag is string tagString)
42 ChildFound(child);
43 LoadSettingProfile(child);
44 }
45 }
46
47 public static void ChildFound(DependencyObject child)
48 {
49 if (child is SwitchButton switchButton && switchButton.Tag is string switchButtonTagPath)
50 {
51 switchButton.IsChecked = ProfileHelper.GetProfileValue<bool>(switchButtonTagPath);
52 }
53 else if (child is TextBox textBox && textBox.Tag is string textEditorTagPath)
54 {
55 switch (textEditorTagPath)
37 56 {
38 switchButton.IsChecked = ProfileHelper.GetProfileValue<bool>(tagString);
57 case "XFEToolBox.Profiles.CrossVersionProfiles.ConsoleProfile.ConsolePort":
58 ReadWithDefaultValue(textBox, 3280);
59 break;
60 case "XFEToolBox.Profiles.CrossVersionProfiles.ConsoleProfile.MaxLine":
61 ReadWithDefaultValue(textBox, 8000);
62 break;
63 case "XFEToolBox.Profiles.CrossVersionProfiles.DownloadProfile.DownloadThread":
64 ReadWithDefaultValue(textBox, 9);
65 break;
66 default:
67 textBox.Text = ProfileHelper.GetProfileValue<string>(textEditorTagPath);
68 break;
39 69 }
40 LoadSettingProfile(child);
70 }
71 else if (child is PasswordHintTextBox passwordHintTextBox && passwordHintTextBox.Tag is string passwordTagPath)
72 {
73 passwordHintTextBox.Password = ProfileHelper.GetProfileValue<string>(passwordTagPath) ?? string.Empty;
74 }
75 }
76
77 private static void ReadWithDefaultValue<T>(TextBox textBox, T defaultValue) where T : struct
78 {
79 if (textBox.Tag is string commandPath)
80 {
81 var value = ProfileHelper.GetProfileValue<T>(commandPath);
82 textBox.Text = value.Equals(defaultValue) ? string.Empty : value.ToString();
83 }
84 }
85
86 private static void SetWithDefaultValue<T>(TextEditor textEditor, T defaultValue) where T : struct
87 {
88 if (textEditor.Tag is string commandPath)
89 {
90 if (int.TryParse(textEditor.Text, out var currentValue))
91 {
92 ProfileHelper.SetProfileValue(commandPath, currentValue);
93 }
94 else if (textEditor.Text == string.Empty || textEditor.Text is null)
95 {
96 ProfileHelper.SetProfileValue(commandPath, defaultValue);
97 }
98 }
99 }
100
101 public void TextChange(object sender, TextChangedEventArgs e)
102 {
103 if (e.OriginalSource is TextBox textBox && textBox.Name == "mainTextBox" && sender is TextEditor textEditor && textEditor.Tag is string commandPath)
104 {
105 switch (commandPath)
106 {
107 case "XFEToolBox.Profiles.CrossVersionProfiles.ConsoleProfile.ConsolePort":
108 SetWithDefaultValue(textEditor, 3280);
109 break;
110 case "XFEToolBox.Profiles.CrossVersionProfiles.ConsoleProfile.MaxLine":
111 SetWithDefaultValue(textEditor, 8000);
112 break;
113 case "XFEToolBox.Profiles.CrossVersionProfiles.DownloadProfile.DownloadThread":
114 SetWithDefaultValue(textEditor, 9);
115 break;
116 default:
117 ProfileHelper.SetProfileValue(commandPath, textBox.Text);
118 break;
119 }
120 }
121 }
122
123 public void PasswordChange(object sender, PasswordChangeEventArgs e)
124 {
125 if (sender is PasswordHintTextBox passwordHintTextBox && passwordHintTextBox.Tag is string commandPath)
126 {
127 switch (commandPath)
128 {
129 default:
130 ProfileHelper.SetProfileValue(commandPath, e.Password);
131 break;
132 }
133 }
134 }
135
136 public void ScrollChanged(object sender, ScrollChangedEventArgs e) => CheckTargetScrollTab(ViewPage);
137
138 public void CheckTargetScrollTab(DependencyObject parent)
139 {
140 if (parent is null)
141 return;
142 int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
143 for (int i = 0; i < childrenCount; i++)
144 {
145 var child = VisualTreeHelper.GetChild(parent, i);
146 if (child is TabUnderLineButton tabUnderLineButton && tabUnderLineButton.Tag is string tabTag && tabUnderLineButton.IsChecked is false && ViewPage.FindName($"{tabTag}SettingBlock") is TextBlock textBlock)
147 {
148 var target = textBlock.TranslatePoint(new(), ViewPage.scrollViewer).Y;
149 if (target <= 0 && target >= -50)
150 tabUnderLineButton.IsChecked = true;
151 }
152 CheckTargetScrollTab(child);
41 153 }
42 154 }
43 155
@@ -72,11 +184,39 @@ public partial class SettingPageViewModel(SettingPage viewPage) : ObservableObje
72 184 ProfileHelper.SetProfileValue(commandPath!, value.IsChecked.Value);
73 185 }
74 186 }
187
75 188 [RelayCommand]
76 189 async Task ClearCache()
77 190 {
78 191 Directory.Delete(AppPath.CacheProfile, true);
79 192 await Task.Run(CalculateFileSize);
80 193 }
194
195 [RelayCommand]
196 static void OpenDownloadDirectory() => Process.Start("explorer.exe", DownloadProfile.DownloadDirectory);
197
198 [RelayCommand]
199 void ChoiceDownloadDirectory()
200 {
201 var directoryOpenDialog = new OpenFolderDialog()
202 {
203 DefaultDirectory = DownloadProfile.DownloadDirectory,
204 Multiselect = false,
205 Title = "选择下载的目标文件夹位置"
206 };
207 var result = directoryOpenDialog.ShowDialog();
208 if (result is true)
209 {
210 DownloadProfile.DownloadDirectory = directoryOpenDialog.FolderName;
211 DownloadDirectory = $"下载目录:{DownloadProfile.DownloadDirectory}";
212 }
213 }
214
215 [RelayCommand]
216 void TabClicked(TabUnderLineButton value)
217 {
218 if (value.Tag is string tabTag && ViewPage.FindName($"{tabTag}SettingBlock") is TextBlock textBlock)
219 ViewPage.scrollViewer.ScrollToVerticalOffset(ViewPage.scrollViewer.VerticalOffset + textBlock.TranslatePoint(new(), ViewPage.scrollViewer).Y);
220 }
81 221 #endregion
82 222 }
Modified XFEToolBox/Views/Controls/HintTextBox.cs +2 -8
@@ -4,20 +4,14 @@ using System.Windows.Media;
4 4
5 5 namespace XFEToolBox.Views.Controls;
6 6
7 /// <summary>
8 /// HintTextBox.xaml 的交互逻辑
9 /// </summary>
10 public partial class HintTextBox : TextBox
7 public class HintTextBox : TextBox
11 8 {
12 public HintTextBox()
13 {
14 }
15 9 public string HintText
16 10 {
17 11 get { return (string)GetValue(HintTextProperty); }
18 12 set { SetValue(HintTextProperty, value); }
19 13 }
20 public static readonly DependencyProperty HintTextProperty = DependencyProperty.Register("HintText", typeof(string), typeof(HintTextBox), new PropertyMetadata("请输入文本..."));
14 public static readonly DependencyProperty HintTextProperty = DependencyProperty.Register("HintText", typeof(string), typeof(HintTextBox), new PropertyMetadata("请输入文本"));
21 15
22 16 public Brush HintForeground
23 17 {
Added XFEToolBox/Views/Controls/PasswordHintTextBox.xaml +84 -0
@@ -0,0 +1,84 @@
1 <UserControl x:Class="XFEToolBox.Views.Controls.PasswordHintTextBox"
2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6 xmlns:local="clr-namespace:XFEToolBox.Views.Controls"
7 mc:Ignorable="d"
8 d:DesignHeight="450" d:DesignWidth="800" Name="passwordHintTextBox">
9 <Border CornerRadius="{Binding EditorCornerRadius, ElementName=passwordHintTextBox}" BorderBrush="{Binding EditorBorderBrush, ElementName=passwordHintTextBox}" BorderThickness="{Binding EditorBorderThickness, ElementName=passwordHintTextBox}" Background="{Binding Background, ElementName=passwordHintTextBox}" Padding="5,0,0,0">
10 <Grid>
11 <Grid.ColumnDefinitions>
12 <ColumnDefinition Width="*"/>
13 <ColumnDefinition Width="25"/>
14 </Grid.ColumnDefinitions>
15 <Grid.RowDefinitions>
16 <RowDefinition Height="25"/>
17 </Grid.RowDefinitions>
18 <local:HintTextBox x:Name="hintTextBox" BorderThickness="0" Background="{Binding Background, ElementName=passwordHintTextBox}" Foreground="{Binding Foreground, ElementName=passwordHintTextBox}" HintBackground="{Binding HintBackground, ElementName=passwordHintTextBox}" Text="{Binding Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ElementName=passwordHintTextBox}" HintForeground="{Binding HintForeground, ElementName=passwordHintTextBox}" HintText="{Binding HintText, ElementName=passwordHintTextBox}" HintFontSize="{Binding HintFontSize, ElementName=passwordHintTextBox}" HintFontFamily="{Binding HintFontFamily, ElementName=passwordHintTextBox}" HintFontWeight="{Binding HintFontWeight, ElementName=passwordHintTextBox}" HintTextHorizontalAlignment="{Binding HintTextHorizontalAlignment, ElementName=passwordHintTextBox}" HintTextVerticalAlignment="{Binding HintTextVerticalAlignment, ElementName=passwordHintTextBox}" HintTextMargin="{Binding HintTextMargin, ElementName=passwordHintTextBox}" HintTextOpacity="{Binding HintTextOpacity, ElementName=passwordHintTextBox}" CaretBrush="{Binding CaretBrush, ElementName=passwordHintTextBox}" SelectionBrush="{Binding SelectionBrush, ElementName=passwordHintTextBox}" SelectionTextBrush="{Binding SelectionTextBrush, ElementName=passwordHintTextBox}" IsReadOnly="{Binding IsReadOnly, ElementName=passwordHintTextBox}" IsReadOnlyCaretVisible="{Binding IsReadOnlyCaretVisible, ElementName=passwordHintTextBox}" HorizontalContentAlignment="{Binding HorizontalContentAlignment, ElementName=passwordHintTextBox}" VerticalContentAlignment="{Binding VerticalContentAlignment, ElementName=passwordHintTextBox}" HorizontalScrollBarVisibility="{Binding HorizontalScrollBarVisibility, ElementName=passwordHintTextBox}" VerticalScrollBarVisibility="{Binding VerticalScrollBarVisibility, ElementName=passwordHintTextBox}" AcceptsReturn="{Binding AcceptsReturn, ElementName=passwordHintTextBox}" AcceptsTab="{Binding AcceptsTab, ElementName=passwordHintTextBox}" IsEnabled="{Binding IsEnabled, ElementName=passwordHintTextBox}" IsInactiveSelectionHighlightEnabled="{Binding IsInactiveSelectionHighlightEnabled, ElementName=passwordHintTextBox}" UndoLimit="{Binding UndoLimit, ElementName=passwordHintTextBox}" IsUndoEnabled="{Binding IsUndoEnabled, ElementName=passwordHintTextBox}" TextWrapping="{Binding TextWrapping, ElementName=passwordHintTextBox}" TextAlignment="{Binding TextAlignment, ElementName=passwordHintTextBox}" TextDecorations="{Binding TextDecorations, ElementName=passwordHintTextBox}" VerticalAlignment="Center"/>
19 <Button x:Name="visibleButton" FocusVisualStyle="{x:Null}" Grid.Column="1" Width="23" Height="23" VerticalAlignment="Center" HorizontalAlignment="Center">
20 <Button.Style>
21 <Style TargetType="Button">
22 <Setter Property="Template">
23 <Setter.Value>
24 <ControlTemplate>
25 <Grid>
26 <Border x:Name="mainBorder" CornerRadius="8" Background="#9898e7" Opacity="0.15"/>
27 <ContentPresenter Content="{Binding Content, ElementName=visibleButton}"/>
28 </Grid>
29 <ControlTemplate.Triggers>
30 <EventTrigger RoutedEvent="MouseEnter">
31 <BeginStoryboard>
32 <Storyboard>
33 <DoubleAnimation Storyboard.TargetName="mainBorder" Storyboard.TargetProperty="Opacity" To="0.3" Duration="0:0:0.3">
34 <DoubleAnimation.EasingFunction>
35 <CubicEase EasingMode="EaseOut"/>
36 </DoubleAnimation.EasingFunction>
37 </DoubleAnimation>
38 </Storyboard>
39 </BeginStoryboard>
40 </EventTrigger>
41 <EventTrigger RoutedEvent="MouseLeave">
42 <BeginStoryboard>
43 <Storyboard>
44 <DoubleAnimation Storyboard.TargetName="mainBorder" Storyboard.TargetProperty="Opacity" To="0.15" Duration="0:0:0.3">
45 <DoubleAnimation.EasingFunction>
46 <CubicEase EasingMode="EaseOut"/>
47 </DoubleAnimation.EasingFunction>
48 </DoubleAnimation>
49 </Storyboard>
50 </BeginStoryboard>
51 </EventTrigger>
52 <EventTrigger RoutedEvent="PreviewMouseLeftButtonDown">
53 <BeginStoryboard>
54 <Storyboard>
55 <DoubleAnimation Storyboard.TargetName="mainBorder" Storyboard.TargetProperty="Opacity" To="0.5" Duration="0:0:0.3">
56 <DoubleAnimation.EasingFunction>
57 <CubicEase EasingMode="EaseOut"/>
58 </DoubleAnimation.EasingFunction>
59 </DoubleAnimation>
60 </Storyboard>
61 </BeginStoryboard>
62 </EventTrigger>
63 <EventTrigger RoutedEvent="PreviewMouseLeftButtonUp">
64 <BeginStoryboard>
65 <Storyboard>
66 <DoubleAnimation Storyboard.TargetName="mainBorder" Storyboard.TargetProperty="Opacity" To="0.3" Duration="0:0:0.3">
67 <DoubleAnimation.EasingFunction>
68 <CubicEase EasingMode="EaseOut"/>
69 </DoubleAnimation.EasingFunction>
70 </DoubleAnimation>
71 </Storyboard>
72 </BeginStoryboard>
73 </EventTrigger>
74 </ControlTemplate.Triggers>
75 </ControlTemplate>
76 </Setter.Value>
77 </Setter>
78 </Style>
79 </Button.Style>
80 <Image x:Name="visibilityImage" Source="/Resources/Image/invisible.png" Margin="3" FocusVisualStyle="{x:Null}"/>
81 </Button>
82 </Grid>
83 </Border>
84 </UserControl>
Added XFEToolBox/Views/Controls/PasswordHintTextBox.xaml.cs +339 -0
@@ -0,0 +1,339 @@
1 using System.Diagnostics;
2 using System.Windows;
3 using System.Windows.Controls;
4 using System.Windows.Media;
5 using System.Windows.Media.Imaging;
6
7 namespace XFEToolBox.Views.Controls;
8
9 public partial class PasswordHintTextBox : UserControl
10 {
11 private bool passwordVisibleChanging = false;
12 #region DependencyProperty
13 public string Text
14 {
15 get { return (string)GetValue(TextProperty); }
16 set { SetValue(TextProperty, value); }
17 }
18 public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(PasswordHintTextBox), new PropertyMetadata(string.Empty));
19
20 public string Password
21 {
22 get { return (string)GetValue(PasswordProperty); }
23 set
24 {
25 SetValue(PasswordProperty, value);
26 passwordVisibleChanging = true;
27 if (PasswordVisible)
28 {
29 Text = Password;
30 }
31 else
32 {
33 Text = GetMaskText(Password.Length);
34 }
35 PasswordChange?.Invoke(this, new(Password, default!));
36 passwordVisibleChanging = false;
37 }
38 }
39 public static readonly DependencyProperty PasswordProperty = DependencyProperty.Register("Password", typeof(string), typeof(PasswordHintTextBox), new PropertyMetadata(string.Empty));
40
41 public string HintText
42 {
43 get { return (string)GetValue(HintTextProperty); }
44 set { SetValue(HintTextProperty, value); }
45 }
46 public static readonly DependencyProperty HintTextProperty = DependencyProperty.Register("HintText", typeof(string), typeof(PasswordHintTextBox), new PropertyMetadata("请输入密码"));
47
48 public string SelectedText
49 {
50 get { return (string)GetValue(SelectedTextProperty); }
51 set { SetValue(SelectedTextProperty, value); }
52 }
53 public static readonly DependencyProperty SelectedTextProperty = DependencyProperty.Register("SelectedText", typeof(string), typeof(PasswordHintTextBox), new PropertyMetadata(string.Empty));
54
55 public string PasswordMask
56 {
57 get { return (string)GetValue(PasswordMaskProperty); }
58 set { SetValue(PasswordMaskProperty, value); }
59 }
60 public static readonly DependencyProperty PasswordMaskProperty = DependencyProperty.Register("PasswordMask", typeof(string), typeof(PasswordHintTextBox), new PropertyMetadata("●"));
61
62 public bool PasswordVisible
63 {
64 get { return (bool)GetValue(PasswordVisibleProperty); }
65 set
66 {
67 SetValue(PasswordVisibleProperty, value);
68
69 }
70 }
71 public static readonly DependencyProperty PasswordVisibleProperty = DependencyProperty.Register("PasswordVisible", typeof(bool), typeof(PasswordHintTextBox), new PropertyMetadata(false));
72
73 public bool IsReadOnly
74 {
75 get { return (bool)GetValue(IsReadOnlyProperty); }
76 set { SetValue(IsReadOnlyProperty, value); }
77 }
78 public static readonly DependencyProperty IsReadOnlyProperty = DependencyProperty.Register("IsReadOnly", typeof(bool), typeof(PasswordHintTextBox), new PropertyMetadata(false));
79
80 public bool IsReadOnlyCaretVisible
81 {
82 get { return (bool)GetValue(IsReadOnlyCaretVisibleProperty); }
83 set { SetValue(IsReadOnlyCaretVisibleProperty, value); }
84 }
85 public static readonly DependencyProperty IsReadOnlyCaretVisibleProperty = DependencyProperty.Register("IsReadOnlyCaretVisible", typeof(bool), typeof(PasswordHintTextBox), new PropertyMetadata(false));
86
87 public bool IsInactiveSelectionHighlightEnabled
88 {
89 get { return (bool)GetValue(IsInactiveSelectionHighlightEnabledProperty); }
90 set { SetValue(IsInactiveSelectionHighlightEnabledProperty, value); }
91 }
92 public static readonly DependencyProperty IsInactiveSelectionHighlightEnabledProperty = DependencyProperty.Register("IsInactiveSelectionHighlightEnabled", typeof(bool), typeof(PasswordHintTextBox), new PropertyMetadata(false));
93
94 public bool AcceptsReturn
95 {
96 get { return (bool)GetValue(AcceptsReturnProperty); }
97 set { SetValue(AcceptsReturnProperty, value); }
98 }
99 public static readonly DependencyProperty AcceptsReturnProperty = DependencyProperty.Register("AcceptsReturn", typeof(bool), typeof(PasswordHintTextBox), new PropertyMetadata(false));
100
101 public bool AcceptsTab
102 {
103 get { return (bool)GetValue(AcceptsTabProperty); }
104 set { SetValue(AcceptsTabProperty, value); }
105 }
106 public static readonly DependencyProperty AcceptsTabProperty = DependencyProperty.Register("AcceptsTab", typeof(bool), typeof(PasswordHintTextBox), new PropertyMetadata(false));
107
108 public bool IsUndoEnabled
109 {
110 get { return (bool)GetValue(IsUndoEnabledProperty); }
111 set { SetValue(IsUndoEnabledProperty, value); }
112 }
113 public static readonly DependencyProperty IsUndoEnabledProperty = DependencyProperty.Register("IsUndoEnabled", typeof(bool), typeof(PasswordHintTextBox), new PropertyMetadata(false));
114
115 public double HintFontSize
116 {
117 get { return (double)GetValue(HintFontSizeProperty); }
118 set { SetValue(HintFontSizeProperty, value); }
119 }
120 public static readonly DependencyProperty HintFontSizeProperty = DependencyProperty.Register("HintFontSize", typeof(double), typeof(PasswordHintTextBox), new PropertyMetadata(13d));
121
122 public double HintTextOpacity
123 {
124 get { return (double)GetValue(HintTextOpacityProperty); }
125 set { SetValue(HintTextOpacityProperty, value); }
126 }
127 public static readonly DependencyProperty HintTextOpacityProperty = DependencyProperty.Register("HintTextOpacity", typeof(double), typeof(PasswordHintTextBox), new PropertyMetadata(0.5d));
128
129 public int UndoLimit
130 {
131 get { return (int)GetValue(UndoLimitProperty); }
132 set { SetValue(UndoLimitProperty, value); }
133 }
134 public static readonly DependencyProperty UndoLimitProperty = DependencyProperty.Register("UndoLimit", typeof(int), typeof(PasswordHintTextBox), new PropertyMetadata(-1));
135
136 public int CaretIndex
137 {
138 get { return (int)GetValue(CaretIndexProperty); }
139 set { SetValue(CaretIndexProperty, value); }
140 }
141 public static readonly DependencyProperty CaretIndexProperty = DependencyProperty.Register("CaretIndex", typeof(int), typeof(PasswordHintTextBox), new PropertyMetadata(-1));
142
143 public int SelectionStart
144 {
145 get { return (int)GetValue(SelectionStartProperty); }
146 set { SetValue(SelectionStartProperty, value); }
147 }
148 public static readonly DependencyProperty SelectionStartProperty = DependencyProperty.Register("SelectionStart", typeof(int), typeof(PasswordHintTextBox), new PropertyMetadata(-1));
149
150 public int SelectionLength
151 {
152 get { return (int)GetValue(SelectionLengthProperty); }
153 set { SetValue(SelectionLengthProperty, value); }
154 }
155 public static readonly DependencyProperty SelectionLengthProperty = DependencyProperty.Register("SelectionLength", typeof(int), typeof(PasswordHintTextBox), new PropertyMetadata(-1));
156
157 public FontFamily HintFontFamily
158 {
159 get { return (FontFamily)GetValue(HintFontFamilyProperty); }
160 set { SetValue(HintFontFamilyProperty, value); }
161 }
162 public static readonly DependencyProperty HintFontFamilyProperty = DependencyProperty.Register("HintFontFamily", typeof(FontFamily), typeof(PasswordHintTextBox), new PropertyMetadata(new FontFamily()));
163
164 public Brush HintForeground
165 {
166 get { return (Brush)GetValue(HintForegroundProperty); }
167 set { SetValue(HintForegroundProperty, value); }
168 }
169 public static readonly DependencyProperty HintForegroundProperty = DependencyProperty.Register("HintForeground", typeof(Brush), typeof(PasswordHintTextBox), new PropertyMetadata(new SolidColorBrush(Colors.Black)));
170
171 public Brush HintBackground
172 {
173 get { return (Brush)GetValue(HintBackgroundProperty); }
174 set { SetValue(HintBackgroundProperty, value); }
175 }
176 public static readonly DependencyProperty HintBackgroundProperty = DependencyProperty.Register("HintBackground", typeof(Brush), typeof(PasswordHintTextBox), new PropertyMetadata(new SolidColorBrush(Colors.Transparent)));
177
178 public Brush EditorBorderBrush
179 {
180 get { return (Brush)GetValue(EditorBorderBrushProperty); }
181 set { SetValue(EditorBorderBrushProperty, value); }
182 }
183 public static readonly DependencyProperty EditorBorderBrushProperty = DependencyProperty.Register("EditorBorderBrush", typeof(Brush), typeof(PasswordHintTextBox), new PropertyMetadata(new SolidColorBrush(Color.FromRgb(152, 152, 231))));
184
185 public Brush CaretBrush
186 {
187 get { return (Brush)GetValue(CaretBrushProperty); }
188 set { SetValue(CaretBrushProperty, value); }
189 }
190 public static readonly DependencyProperty CaretBrushProperty = DependencyProperty.Register("CaretBrush", typeof(Brush), typeof(PasswordHintTextBox), new PropertyMetadata(new SolidColorBrush(Color.FromRgb(152, 152, 231))));
191
192 public Brush SelectionBrush
193 {
194 get { return (Brush)GetValue(SelectionBrushProperty); }
195 set { SetValue(SelectionBrushProperty, value); }
196 }
197 public static readonly DependencyProperty SelectionBrushProperty = DependencyProperty.Register("SelectionBrush", typeof(Brush), typeof(PasswordHintTextBox), new PropertyMetadata(new SolidColorBrush(Color.FromRgb(152, 152, 231))));
198
199 public Brush SelectionTextBrush
200 {
201 get { return (Brush)GetValue(SelectionTextBrushProperty); }
202 set { SetValue(SelectionTextBrushProperty, value); }
203 }
204 public static readonly DependencyProperty SelectionTextBrushProperty = DependencyProperty.Register("SelectionTextBrush", typeof(Brush), typeof(PasswordHintTextBox), new PropertyMetadata(new SolidColorBrush(Color.FromRgb(152, 152, 231))));
205
206 public TextDecorationCollection TextDecorations
207 {
208 get { return (TextDecorationCollection)GetValue(TextDecorationsProperty); }
209 set { SetValue(TextDecorationsProperty, value); }
210 }
211 public static readonly DependencyProperty TextDecorationsProperty = DependencyProperty.Register("TextDecorations", typeof(TextDecorationCollection), typeof(PasswordHintTextBox), new PropertyMetadata(null));
212
213 public FontWeight HintFontWeight
214 {
215 get { return (FontWeight)GetValue(HintFontWeightProperty); }
216 set { SetValue(HintFontWeightProperty, value); }
217 }
218 public static readonly DependencyProperty HintFontWeightProperty = DependencyProperty.Register("HintFontWeight", typeof(FontWeight), typeof(PasswordHintTextBox), new PropertyMetadata(new FontWeight()));
219
220 public Thickness HintTextMargin
221 {
222 get { return (Thickness)GetValue(HintTextMarginProperty); }
223 set { SetValue(HintTextMarginProperty, value); }
224 }
225 public static readonly DependencyProperty HintTextMarginProperty = DependencyProperty.Register("HintTextMargin", typeof(Thickness), typeof(PasswordHintTextBox), new PropertyMetadata(new Thickness(10, 0, 0, 0)));
226
227 public CornerRadius EditorCornerRadius
228 {
229 get { return (CornerRadius)GetValue(EditorCornerRadiusProperty); }
230 set { SetValue(EditorCornerRadiusProperty, value); }
231 }
232 public static readonly DependencyProperty EditorCornerRadiusProperty = DependencyProperty.Register("EditorCornerRadius", typeof(CornerRadius), typeof(PasswordHintTextBox), new PropertyMetadata(new CornerRadius(10)));
233
234 public Thickness EditorBorderThickness
235 {
236 get { return (Thickness)GetValue(EditorBorderThicknessProperty); }
237 set { SetValue(EditorBorderThicknessProperty, value); }
238 }
239 public static readonly DependencyProperty EditorBorderThicknessProperty = DependencyProperty.Register("EditorBorderThickness", typeof(Thickness), typeof(PasswordHintTextBox), new PropertyMetadata(new Thickness(1)));
240
241 public VerticalAlignment HintTextVerticalAlignment
242 {
243 get { return (VerticalAlignment)GetValue(HintTextVerticalAlignmentProperty); }
244 set { SetValue(HintTextVerticalAlignmentProperty, value); }
245 }
246 public static readonly DependencyProperty HintTextVerticalAlignmentProperty = DependencyProperty.Register("HintTextVerticalAlignment", typeof(VerticalAlignment), typeof(PasswordHintTextBox), new PropertyMetadata(VerticalAlignment.Center));
247
248 public HorizontalAlignment HintTextHorizontalAlignment
249 {
250 get { return (HorizontalAlignment)GetValue(HintTextHorizontalAlignmentProperty); }
251 set { SetValue(HintTextHorizontalAlignmentProperty, value); }
252 }
253 public static readonly DependencyProperty HintTextHorizontalAlignmentProperty = DependencyProperty.Register("HintTextHorizontalAlignment", typeof(HorizontalAlignment), typeof(PasswordHintTextBox), new PropertyMetadata(HorizontalAlignment.Left));
254
255 public ScrollBarVisibility HorizontalScrollBarVisibility
256 {
257 get { return (ScrollBarVisibility)GetValue(HorizontalScrollBarVisibilityProperty); }
258 set { SetValue(HorizontalScrollBarVisibilityProperty, value); }
259 }
260 public static readonly DependencyProperty HorizontalScrollBarVisibilityProperty = DependencyProperty.Register("HorizontalScrollBarVisibility", typeof(ScrollBarVisibility), typeof(PasswordHintTextBox), new PropertyMetadata(ScrollBarVisibility.Hidden));
261
262 public ScrollBarVisibility VerticalScrollBarVisibility
263 {
264 get { return (ScrollBarVisibility)GetValue(VerticalScrollBarVisibilityProperty); }
265 set { SetValue(VerticalScrollBarVisibilityProperty, value); }
266 }
267 public static readonly DependencyProperty VerticalScrollBarVisibilityProperty = DependencyProperty.Register("VerticalScrollBarVisibility", typeof(ScrollBarVisibility), typeof(PasswordHintTextBox), new PropertyMetadata(ScrollBarVisibility.Hidden));
268
269 public TextAlignment TextAlignment
270 {
271 get { return (TextAlignment)GetValue(TextAlignmentProperty); }
272 set { SetValue(TextAlignmentProperty, value); }
273 }
274 public static readonly DependencyProperty TextAlignmentProperty = DependencyProperty.Register("TextAlignment", typeof(TextAlignment), typeof(PasswordHintTextBox), new PropertyMetadata(TextAlignment.Left));
275
276 public TextWrapping TextWrapping
277 {
278 get { return (TextWrapping)GetValue(TextWrappingProperty); }
279 set { SetValue(TextWrappingProperty, value); }
280 }
281 public static readonly DependencyProperty TextWrappingProperty = DependencyProperty.Register("TextWrapping", typeof(TextWrapping), typeof(PasswordHintTextBox), new PropertyMetadata(TextWrapping.NoWrap));
282 #endregion
283
284 public event EventHandler<PasswordChangeEventArgs?>? PasswordChange;
285
286 public PasswordHintTextBox()
287 {
288 InitializeComponent();
289 hintTextBox.TextChanged += HintTextBox_TextChanged;
290 visibleButton.Click += VisibleButton_Click;
291 }
292
293 private string GetMaskText(int length)
294 {
295 string maskText = string.Empty;
296 for (int i = 0; i < length; i++)
297 maskText += PasswordMask;
298 return maskText;
299 }
300
301 private void VisibleButton_Click(object sender, RoutedEventArgs e)
302 {
303 PasswordVisible = !PasswordVisible;
304 passwordVisibleChanging = true;
305 if (PasswordVisible)
306 {
307 visibilityImage.Source = new BitmapImage(new("pack://application:,,,/Resources/Image/visible.png"));
308 Text = Password;
309 }
310 else
311 {
312 visibilityImage.Source = new BitmapImage(new("pack://application:,,,/Resources/Image/invisible.png"));
313 Text = GetMaskText(Text.Length);
314 }
315 passwordVisibleChanging = false;
316 }
317
318 private void HintTextBox_TextChanged(object sender, TextChangedEventArgs e)
319 {
320 if (!passwordVisibleChanging && e.OriginalSource is TextBox textBox && textBox.Name == "mainTextBox")
321 {
322 foreach (var change in e.Changes)
323 {
324 SetValue(PasswordProperty, Password.Remove(change.Offset, change.RemovedLength));
325 SetValue(PasswordProperty, Password.Insert(change.Offset, Text.Substring(change.Offset, change.AddedLength)));
326 if (!PasswordVisible && change.AddedLength > 0)
327 {
328 passwordVisibleChanging = true;
329 Text = Text.Replace(Text.Substring(change.Offset, change.AddedLength), GetMaskText(change.AddedLength));
330 textBox.CaretIndex = change.Offset + change.AddedLength;
331 passwordVisibleChanging = false;
332 }
333 }
334 PasswordChange?.Invoke(this, new(Password, e));
335 }
336 }
337 }
338
339 public record PasswordChangeEventArgs(string Password, TextChangedEventArgs TextChangedEventArgs) { }
Modified XFEToolBox/Views/Controls/RoundButton.cs +2 -2
@@ -19,14 +19,14 @@ public class RoundButton : Button
19 19 get { return (Brush)GetValue(RoundButtonBackgroundProperty); }
20 20 set { SetValue(RoundButtonBackgroundProperty, value); }
21 21 }
22 public static readonly DependencyProperty RoundButtonBackgroundProperty = DependencyProperty.Register("RoundButtonBackground", typeof(Brush), typeof(RoundButton), new PropertyMetadata(new SolidColorBrush(Colors.White)));
22 public static readonly DependencyProperty RoundButtonBackgroundProperty = DependencyProperty.Register("RoundButtonBackground", typeof(Brush), typeof(RoundButton), new PropertyMetadata(new SolidColorBrush(Color.FromRgb(152, 152, 231))));
23 23
24 24 public Brush RoundButtonBorderBrush
25 25 {
26 26 get { return (Brush)GetValue(RoundButtonBorderBrushProperty); }
27 27 set { SetValue(RoundButtonBorderBrushProperty, value); }
28 28 }
29 public static readonly DependencyProperty RoundButtonBorderBrushProperty = DependencyProperty.Register("RoundButtonBorderBrush", typeof(Brush), typeof(RoundButton), new PropertyMetadata(new SolidColorBrush(Colors.White)));
29 public static readonly DependencyProperty RoundButtonBorderBrushProperty = DependencyProperty.Register("RoundButtonBorderBrush", typeof(Brush), typeof(RoundButton), new PropertyMetadata(new SolidColorBrush(Color.FromRgb(152, 152, 231))));
30 30
31 31 public Thickness RoundButtonBorderThickness
32 32 {
Modified XFEToolBox/Views/Pages/ConsolePage.xaml +2 -2
@@ -62,11 +62,11 @@
62 62 </StackPanel>
63 63 </Grid>
64 64 <Border Grid.Column="0" Grid.Row="1" CornerRadius="0,0,15,0" Background="Black" Padding="0,5,3,5">
65 <ScrollViewer x:Name="scrollViewer" x:FieldModifier="internal" VerticalScrollBarVisibility="Auto" IsTabStop="False" ScrollChanged="ScrollViewer_ScrollChanged">
65 <ScrollViewer x:Name="scrollViewer" VerticalScrollBarVisibility="Auto" IsTabStop="False" ScrollChanged="ScrollViewer_ScrollChanged">
66 66 <ScrollViewer.Resources>
67 67 <Style TargetType="ScrollBar" BasedOn="{StaticResource ConsoleScrollBar}"/>
68 68 </ScrollViewer.Resources>
69 <StackPanel x:Name="consoleStackPanel" x:FieldModifier="internal">
69 <StackPanel x:Name="consoleStackPanel">
70 70 </StackPanel>
71 71 </ScrollViewer>
72 72 </Border>
Modified XFEToolBox/Views/Pages/ConsolePage.xaml.cs +1 -1
@@ -12,10 +12,10 @@ public partial class ConsolePage : Page
12 12 public ConsolePageViewModel ViewModel { get; set; }
13 13 public ConsolePage()
14 14 {
15 InitializeComponent();
16 15 ViewModel = new ConsolePageViewModel(this);
17 16 DataContext = ViewModel;
18 17 Current = this;
18 InitializeComponent();
19 19 }
20 20
21 21 private void ScrollViewer_ScrollChanged(object sender, ScrollChangedEventArgs e) => ViewModel.ScrollChanged(sender, e);
Modified XFEToolBox/Views/Pages/DownloadPage.xaml.cs +1 -1
@@ -10,7 +10,7 @@ public partial class DownloadPage : Page
10 10 public static DownloadPage? Current { get; set; } = new();
11 11 public DownloadPage()
12 12 {
13 InitializeComponent();
14 13 Current = this;
14 InitializeComponent();
15 15 }
16 16 }
Modified XFEToolBox/Views/Pages/MainPage.xaml.cs +1 -1
@@ -12,8 +12,8 @@ public partial class MainPage : Page
12 12 public static MainPage? Current { get; set; } = new();
13 13 public MainPage()
14 14 {
15 InitializeComponent();
16 15 Current = this;
16 InitializeComponent();
17 17 }
18 18
19 19 private void Page_Loaded(object sender, System.Windows.RoutedEventArgs e)
Modified XFEToolBox/Views/Pages/SettingPage.xaml +73 -13
@@ -28,22 +28,26 @@
28 28 <RowDefinition Height="*"/>
29 29 </Grid.RowDefinitions>
30 30 <ScrollViewer Grid.Row="0" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Hidden" VerticalAlignment="Center">
31 <StackPanel Orientation="Horizontal">
32 <ctr:TabUnderLineButton x:Name="generalTabUnderLineButton" Margin="0,0,10,0">
31 <StackPanel x:Name="tabUnderLinePanel" Orientation="Horizontal">
32 <ctr:TabUnderLineButton x:Name="generalTabUnderLineButton" Margin="0,0,10,0" Tag="general" Command="{Binding TabClickedCommand}" CommandParameter="{Binding RelativeSource={x:Static RelativeSource.Self}}">
33 33 <TextBlock Text="常规" Style="{StaticResource TabUnderLineText}"/>
34 34 </ctr:TabUnderLineButton>
35 <ctr:TabUnderLineButton>
35 <ctr:TabUnderLineButton Tag="console" Command="{Binding TabClickedCommand}" CommandParameter="{Binding RelativeSource={x:Static RelativeSource.Self}}">
36 36 <TextBlock Text="控制台" Style="{StaticResource TabUnderLineText}"/>
37 37 </ctr:TabUnderLineButton>
38 <ctr:TabUnderLineButton>
38 <ctr:TabUnderLineButton Tag="download" Command="{Binding TabClickedCommand}" CommandParameter="{Binding RelativeSource={x:Static RelativeSource.Self}}">
39 <TextBlock Text="下载" Style="{StaticResource TabUnderLineText}"/>
40 </ctr:TabUnderLineButton>
41 <ctr:TabUnderLineButton Tag="performance" Command="{Binding TabClickedCommand}" CommandParameter="{Binding RelativeSource={x:Static RelativeSource.Self}}">
39 42 <TextBlock Text="性能" Style="{StaticResource TabUnderLineText}"/>
40 43 </ctr:TabUnderLineButton>
41 44 </StackPanel>
42 45 </ScrollViewer>
43 <Border Background="{DynamicResource MainColor}" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Height="1"/>
46 <Border Background="{DynamicResource MainColor}" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Height="1">
47 </Border>
44 48 </Grid>
45 49 </Border>
46 <ScrollViewer Grid.Row="1" Grid.ColumnSpan="3" VerticalScrollBarVisibility="Hidden" HorizontalScrollBarVisibility="Disabled">
50 <ScrollViewer x:Name="scrollViewer" Grid.Row="1" Grid.ColumnSpan="3" VerticalScrollBarVisibility="Hidden" HorizontalScrollBarVisibility="Disabled" ScrollChanged="ScrollViewer_ScrollChanged">
47 51 <Grid>
48 52 <Grid.ColumnDefinitions>
49 53 <ColumnDefinition Width="*"/>
@@ -56,8 +60,8 @@
56 60 <RowDefinition Height="25"/>
57 61 <RowDefinition Height="*"/>
58 62 </Grid.RowDefinitions>
59 <TextBlock VerticalAlignment="Center" Text="常规" Style="{StaticResource TabUnderLineText}" Tag="常规"/>
60 <Border Background="{DynamicResource MainColor}" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Height="1"/>
63 <TextBlock x:Name="generalSettingBlock" VerticalAlignment="Center" Text="常规" Style="{StaticResource TabUnderLineText}"/>
64 <Border Background="{DynamicResource MainColor}" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Height="1" Tag="常规"/>
61 65 <StackPanel Grid.Row="1">
62 66 <ctr:SwitchButton x:Name="autoSelfLaunchSwitch" Command="{Binding SwitchedCommand}" CommandParameter="{Binding RelativeSource={x:Static RelativeSource.Self}}" Tag="XFEToolBox.Profiles.CrossVersionProfiles.SystemProfile.AutoSelfLaunch">
63 67 <TextBlock Text="开机自启动"/>
@@ -72,13 +76,34 @@
72 76 <RowDefinition Height="25"/>
73 77 <RowDefinition Height="*"/>
74 78 </Grid.RowDefinitions>
75 <TextBlock VerticalAlignment="Center" Text="控制台" Style="{StaticResource TabUnderLineText}" Tag="控制台"/>
79 <TextBlock x:Name="consoleSettingBlock" VerticalAlignment="Center" Text="控制台" Style="{StaticResource TabUnderLineText}"/>
76 80 <Border Background="{DynamicResource MainColor}" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Height="1"/>
77 81 <StackPanel Grid.Row="1">
78 <ctr:TextEditor Style="{StaticResource TextEditor}" Margin="0,10" Padding="5" HintText="3280"/>
82 <Grid>
83 <Grid.RowDefinitions>
84 <RowDefinition Height="*"/>
85 <RowDefinition Height="*"/>
86 </Grid.RowDefinitions>
87 <Grid.ColumnDefinitions>
88 <ColumnDefinition Width="Auto"/>
89 <ColumnDefinition Width="*"/>
90 </Grid.ColumnDefinitions>
91 <TextBlock Margin="0,10" Text="控制台端口:" VerticalAlignment="Center" HorizontalAlignment="Left"/>
92 <ctr:TextEditor Grid.Column="1" CaretBrush="{DynamicResource MainColor}" SelectionBrush="{DynamicResource MainColor}" Margin="10,0,0,0" Padding="5" HintText="3280" HintTextHorizontalAlignment="Center" Width="80" HorizontalAlignment="Left" TextChanged="TextEditor_TextChanged" Tag="XFEToolBox.Profiles.CrossVersionProfiles.ConsoleProfile.ConsolePort" VerticalAlignment="Center"/>
93 <TextBlock Margin="0,10" Grid.Row="1" Text="连接密码:" VerticalAlignment="Center" HorizontalAlignment="Left"/>
94 <ctr:PasswordHintTextBox Grid.Row="1" Grid.Column="1" CaretBrush="{DynamicResource MainColor}" SelectionBrush="{DynamicResource MainColor}" Margin="10,0,0,0" Padding="0" HintText="默认为空" Width="120" HorizontalAlignment="Left" PasswordChange="PasswordHintTextBox_PasswordChange" Tag="XFEToolBox.Profiles.CrossVersionProfiles.ConsoleProfile.ConsolePassword" VerticalAlignment="Center"/>
95 </Grid>
79 96 <ctr:SwitchButton Command="{Binding SwitchedCommand}" CommandParameter="{Binding RelativeSource={x:Static RelativeSource.Self}}" Tag="XFEToolBox.Profiles.CrossVersionProfiles.ConsoleProfile.LocalHostOnly">
80 97 <TextBlock Text="只对本地回环开放(localhost)"/>
81 98 </ctr:SwitchButton>
99 <Grid>
100 <Grid.ColumnDefinitions>
101 <ColumnDefinition Width="Auto"/>
102 <ColumnDefinition Width="*"/>
103 </Grid.ColumnDefinitions>
104 <TextBlock Margin="0,10" Text="控制台最大显示行数 (-1为不设上限):" VerticalAlignment="Center" HorizontalAlignment="Left"/>
105 <ctr:TextEditor Grid.Column="1" CaretBrush="{DynamicResource MainColor}" SelectionBrush="{DynamicResource MainColor}" Margin="10,0,0,0" Padding="5" HintText="8000" HintTextHorizontalAlignment="Center" Width="80" HorizontalAlignment="Left" TextChanged="TextEditor_TextChanged" Tag="XFEToolBox.Profiles.CrossVersionProfiles.ConsoleProfile.MaxLine" VerticalAlignment="Center"/>
106 </Grid>
82 107 </StackPanel>
83 108 </Grid>
84 109 <Grid Margin="0,20">
@@ -86,8 +111,43 @@
86 111 <RowDefinition Height="25"/>
87 112 <RowDefinition Height="*"/>
88 113 </Grid.RowDefinitions>
89 <TextBlock VerticalAlignment="Center" Text="性能" Style="{StaticResource TabUnderLineText}" Tag="性能"/>
90 <Border Background="{DynamicResource MainColor}" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Height="1"/>
114 <TextBlock x:Name="downloadSettingBlock" VerticalAlignment="Center" Text="下载" Style="{StaticResource TabUnderLineText}"/>
115 <Border Background="{DynamicResource MainColor}" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Height="1" Tag="下载"/>
116 <StackPanel Grid.Row="1">
117 <ctr:SwitchButton x:Name="testSwitcher" Command="{Binding SwitchedCommand}" CommandParameter="{Binding RelativeSource={x:Static RelativeSource.Self}}" Tag="XFEToolBox.Profiles.CrossVersionProfiles.DownloadProfile.UseNormalDownloader">
118 <TextBlock Text="使用普通下载模式(不加速)"/>
119 </ctr:SwitchButton>
120 <Grid Margin="0,10">
121 <Grid.ColumnDefinitions>
122 <ColumnDefinition Width="*" MaxWidth="300"/>
123 <ColumnDefinition Width="Auto"/>
124 <ColumnDefinition Width="Auto"/>
125 </Grid.ColumnDefinitions>
126 <TextBlock Text="{Binding DownloadDirectory}" VerticalAlignment="Center" HorizontalAlignment="Left" TextTrimming="CharacterEllipsis"/>
127 <ctr:RoundButton Grid.Column="1" Command="{Binding OpenDownloadDirectoryCommand}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5,0">
128 <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="打开目录" Margin="4" Foreground="{DynamicResource MainColor}"/>
129 </ctr:RoundButton>
130 <ctr:RoundButton Grid.Column="2" Command="{Binding ChoiceDownloadDirectoryCommand}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5,0">
131 <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="更改目录" Margin="4" Foreground="{DynamicResource MainColor}"/>
132 </ctr:RoundButton>
133 </Grid>
134 <Grid Margin="0,10">
135 <Grid.ColumnDefinitions>
136 <ColumnDefinition Width="Auto"/>
137 <ColumnDefinition Width="*"/>
138 </Grid.ColumnDefinitions>
139 <TextBlock Text="加速下载线程数量:" VerticalAlignment="Center" HorizontalAlignment="Left"/>
140 <ctr:TextEditor Grid.Column="1" CaretBrush="{DynamicResource MainColor}" SelectionBrush="{DynamicResource MainColor}" Margin="10,0,0,0" Padding="5" HintText="推荐为9个" HintTextHorizontalAlignment="Center" Width="80" HorizontalAlignment="Left" TextChanged="TextEditor_TextChanged" Tag="XFEToolBox.Profiles.CrossVersionProfiles.DownloadProfile.DownloadThread" VerticalAlignment="Center"/>
141 </Grid>
142 </StackPanel>
143 </Grid>
144 <Grid Margin="0,20">
145 <Grid.RowDefinitions>
146 <RowDefinition Height="25"/>
147 <RowDefinition Height="*"/>
148 </Grid.RowDefinitions>
149 <TextBlock x:Name="performanceSettingBlock" VerticalAlignment="Center" Text="性能" Style="{StaticResource TabUnderLineText}"/>
150 <Border Background="{DynamicResource MainColor}" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Height="1" Tag="性能"/>
91 151 <StackPanel Grid.Row="1">
92 152 <TextBlock Text="储存使用" FontWeight="Bold" Margin="0,10,0,5"/>
93 153 <Border BorderBrush="{DynamicResource MainColor}" BorderThickness="1" Padding="10" CornerRadius="10" HorizontalAlignment="Left">
@@ -95,7 +155,7 @@
95 155 <TextBlock Text="缓存配置文件:" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left"/>
96 156 <StackPanel Orientation="Horizontal">
97 157 <TextBlock Text="{Binding CacheProfileSize}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
98 <ctr:RoundButton RoundButtonBackground="{DynamicResource MainColor}" RoundButtonBorderBrush="{DynamicResource MainColor}" Margin="10,0,0,0" Command="{Binding ClearCacheCommand}">
158 <ctr:RoundButton Margin="10,0,0,0" Command="{Binding ClearCacheCommand}">
99 159 <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="清理缓存" Margin="5,0" Foreground="{DynamicResource MainColor}"/>
100 160 </ctr:RoundButton>
101 161 </StackPanel>
Modified XFEToolBox/Views/Pages/SettingPage.xaml.cs +15 -3
@@ -1,5 +1,10 @@
1 using System.Windows.Controls;
1 using System.Diagnostics;
2 using System.Windows;
3 using System.Windows.Controls;
4 using XFEExtension.NetCore.StringExtension;
5 using XFEToolBox.Profiles.CrossVersionProfiles;
2 6 using XFEToolBox.ViewModel;
7 using XFEToolBox.Views.Controls;
3 8
4 9 namespace XFEToolBox.Views.Pages;
5 10
@@ -12,13 +17,13 @@ public partial class SettingPage : Page
12 17 public SettingPageViewModel ViewModel { get; set; }
13 18 public SettingPage()
14 19 {
15 InitializeComponent();
16 20 ViewModel = new(this);
17 21 DataContext = ViewModel;
18 22 Current = this;
23 InitializeComponent();
19 24 }
20 25
21 private async void Page_Loaded(object sender, System.Windows.RoutedEventArgs e)
26 private async void Page_Loaded(object sender, RoutedEventArgs e)
22 27 {
23 28 await Task.Run(() =>
24 29 {
@@ -28,6 +33,13 @@ public partial class SettingPage : Page
28 33 SettingPageViewModel.LoadSettingProfile(this);
29 34 });
30 35 ViewModel.CalculateFileSize();
36 ViewModel.DownloadDirectory = $"下载目录:{DownloadProfile.DownloadDirectory}";
31 37 });
32 38 }
39
40 private void TextEditor_TextChanged(object sender, TextChangedEventArgs e) => ViewModel.TextChange(sender, e);
41
42 private void PasswordHintTextBox_PasswordChange(object sender, PasswordChangeEventArgs e) => ViewModel.PasswordChange(sender, e);
43
44 private void ScrollViewer_ScrollChanged(object sender, ScrollChangedEventArgs e) => ViewModel.ScrollChanged(sender, e);
33 45 }
Modified XFEToolBox/Views/Pages/ToolBoxPage.xaml.cs +1 -1
@@ -10,7 +10,7 @@ public partial class ToolBoxPage : Page
10 10 public static ToolBoxPage? Current { get; set; } = new();
11 11 public ToolBoxPage()
12 12 {
13 InitializeComponent();
14 13 Current = this;
14 InitializeComponent();
15 15 }
16 16 }
Modified XFEToolBox/XFEToolBox.csproj +4 -0
@@ -20,6 +20,7 @@
20 20 <None Remove="Resources\Image\corner.png" />
21 21 <None Remove="Resources\Image\download.png" />
22 22 <None Remove="Resources\Image\grid.png" />
23 <None Remove="Resources\Image\invisible.png" />
23 24 <None Remove="Resources\Image\min.png" />
24 25 <None Remove="Resources\Image\restart.png" />
25 26 <None Remove="Resources\Image\setting.png" />
@@ -27,6 +28,7 @@
27 28 <None Remove="Resources\Image\stop.png" />
28 29 <None Remove="Resources\Image\tabline.png" />
29 30 <None Remove="Resources\Image\toolbox.png" />
31 <None Remove="Resources\Image\visible.png" />
30 32 <None Remove="Resources\Image\wrench.png" />
31 33 </ItemGroup>
32 34
@@ -49,6 +51,7 @@
49 51 <Resource Include="Resources\Image\corner.png" />
50 52 <Resource Include="Resources\Image\download.png" />
51 53 <Resource Include="Resources\Image\grid.png" />
54 <Resource Include="Resources\Image\invisible.png" />
52 55 <Resource Include="Resources\Image\min.png" />
53 56 <Resource Include="Resources\Image\restart.png" />
54 57 <Resource Include="Resources\Image\setting.png" />
@@ -69,6 +72,7 @@
69 72 <ItemGroup>
70 73 <Resource Include="Resources\Icon\XFEToolBoxSplashScreen.png" />
71 74 <Resource Include="Resources\Image\toolbox.png" />
75 <Resource Include="Resources\Image\visible.png" />
72 76 <Resource Include="Resources\Image\wrench.png" />
73 77 </ItemGroup>
74 78