返回提交历史

XFEstudio/MyFirstRespo

修复平滑滚动后的标签滚动bug

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

代码差异

7 个文件 +58 -27
Modified XFEToolBox/Resources/Image/steam_logo.png +0 -0
二进制文件已变更,无法进行逐行预览。
Modified XFEToolBox/ViewModel/Pages/SettingPageViewModel.cs +39 -9
@@ -29,6 +29,7 @@ public partial class SettingPageViewModel(SettingPage viewPage) : ObservableObje
29 29 string totalProfileSize = "计算中...";
30 30 [ObservableProperty]
31 31 string downloadDirectory = "目标下载目录:";
32 bool ignoreNextScroll = false;
32 33 public SettingPage ViewPage { get; set; } = viewPage;
33 34
34 35 public static void LoadSettingProfile(DependencyObject parent)
@@ -137,20 +138,46 @@ public partial class SettingPageViewModel(SettingPage viewPage) : ObservableObje
137 138
138 139 public void CheckTargetScrollTab(DependencyObject parent)
139 140 {
141 if (!ignoreNextScroll)
142 {
143 var results = FindType<TabUnderLineButton>(parent);
144 var bestResult = results.FirstOrDefault();
145 double mostNearDistance = double.MinValue;
146 foreach (var tabUnderLineButton in results)
147 {
148 if (tabUnderLineButton.Tag is string tabTag && ViewPage.FindName($"{tabTag}SettingBlock") is TextBlock textBlock)
149 {
150 var target = textBlock.TranslatePoint(new(), ViewPage.scrollViewer).Y;
151 if (target <= 20 && target > mostNearDistance)
152 {
153 mostNearDistance = target;
154 bestResult = tabUnderLineButton;
155 }
156 }
157 }
158 bestResult.IsChecked = true;
159 }
160 else
161 {
162 ignoreNextScroll = false;
163 }
164 }
165
166 public List<T> FindType<T>(DependencyObject parent) where T : DependencyObject
167 {
168 var list = new List<T>();
140 169 if (parent is null)
141 return;
170 return list;
142 171 int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
143 172 for (int i = 0; i < childrenCount; i++)
144 173 {
145 174 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);
175 if (child is T tChild)
176 list.Add(tChild);
177 else
178 list.AddRange(FindType<T>(child));
153 179 }
180 return list;
154 181 }
155 182
156 183 public void CalculateFileSize()
@@ -188,7 +215,7 @@ public partial class SettingPageViewModel(SettingPage viewPage) : ObservableObje
188 215 [RelayCommand]
189 216 async Task ClearCache()
190 217 {
191 await TaskManager.Run(() => Directory.Delete(AppPath.CacheProfile, true),"正在清理缓存");
218 await TaskManager.Run(() => Directory.Delete(AppPath.CacheProfile, true), "正在清理缓存");
192 219 await Task.Run(CalculateFileSize);
193 220 }
194 221
@@ -216,7 +243,10 @@ public partial class SettingPageViewModel(SettingPage viewPage) : ObservableObje
216 243 void TabClicked(TabUnderLineButton value)
217 244 {
218 245 if (value.Tag is string tabTag && ViewPage.FindName($"{tabTag}SettingBlock") is TextBlock textBlock)
246 {
247 ignoreNextScroll = true;
219 248 ViewPage.scrollViewer.ScrollToVerticalOffset(ViewPage.scrollViewer.VerticalOffset + textBlock.TranslatePoint(new(), ViewPage.scrollViewer).Y - 20);
249 }
220 250 }
221 251 #endregion
222 252 }
Renamed XFEToolBox/Views/Controls/MiniToolButton.xaml +1 -1
@@ -1,4 +1,4 @@
1 <UserControl x:Class="XFEToolBox.Views.Controls.ToolButton"
1 <UserControl x:Class="XFEToolBox.Views.Controls.MiniToolButton"
2 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4 4 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Renamed XFEToolBox/Views/Controls/MiniToolButton.xaml.cs +15 -15
@@ -9,7 +9,7 @@ namespace XFEToolBox.Views.Controls;
9 9 /// <summary>
10 10 /// ToolButton.xaml 的交互逻辑
11 11 /// </summary>
12 public partial class ToolButton : UserControl
12 public partial class MiniToolButton : UserControl
13 13 {
14 14 #region DependencyProperty
15 15 public string ToolName
@@ -17,94 +17,94 @@ public partial class ToolButton : UserControl
17 17 get { return (string)GetValue(ToolNameProperty); }
18 18 set { SetValue(ToolNameProperty, value); }
19 19 }
20 public static readonly DependencyProperty ToolNameProperty = DependencyProperty.Register("ToolName", typeof(string), typeof(ToolButton), new PropertyMetadata("未命名工具"));
20 public static readonly DependencyProperty ToolNameProperty = DependencyProperty.Register("ToolName", typeof(string), typeof(MiniToolButton), new PropertyMetadata("未命名工具"));
21 21
22 22 public ImageSource IconSource
23 23 {
24 24 get { return (ImageSource)GetValue(IconSourceProperty); }
25 25 set { SetValue(IconSourceProperty, value); }
26 26 }
27 public static readonly DependencyProperty IconSourceProperty = DependencyProperty.Register("IconSource", typeof(ImageSource), typeof(ToolButton), new PropertyMetadata(new BitmapImage(new("pack://application:,,,/Resources/Image/wrench_tool.png"))));
27 public static readonly DependencyProperty IconSourceProperty = DependencyProperty.Register("IconSource", typeof(ImageSource), typeof(MiniToolButton), new PropertyMetadata(new BitmapImage(new("pack://application:,,,/Resources/Image/wrench_tool.png"))));
28 28
29 29 public Brush TextColor
30 30 {
31 31 get { return (Brush)GetValue(TextColorProperty); }
32 32 set { SetValue(TextColorProperty, value); }
33 33 }
34 public static readonly DependencyProperty TextColorProperty = DependencyProperty.Register("TextColor", typeof(Brush), typeof(ToolButton), new PropertyMetadata(new SolidColorBrush(Colors.White)));
34 public static readonly DependencyProperty TextColorProperty = DependencyProperty.Register("TextColor", typeof(Brush), typeof(MiniToolButton), new PropertyMetadata(new SolidColorBrush(Colors.White)));
35 35
36 36 public Brush ProgressForeground
37 37 {
38 38 get { return (Brush)GetValue(ProgressForegroundProperty); }
39 39 set { SetValue(ProgressForegroundProperty, value); }
40 40 }
41 public static readonly DependencyProperty ProgressForegroundProperty = DependencyProperty.Register("ProgressForeground", typeof(Brush), typeof(ToolButton), new PropertyMetadata(new SolidColorBrush(Color.FromRgb(255, 151, 88))));
41 public static readonly DependencyProperty ProgressForegroundProperty = DependencyProperty.Register("ProgressForeground", typeof(Brush), typeof(MiniToolButton), new PropertyMetadata(new SolidColorBrush(Color.FromRgb(255, 151, 88))));
42 42
43 43 public Brush ProgressBackground
44 44 {
45 45 get { return (Brush)GetValue(ProgressBackgroundProperty); }
46 46 set { SetValue(ProgressBackgroundProperty, value); }
47 47 }
48 public static readonly DependencyProperty ProgressBackgroundProperty = DependencyProperty.Register("ProgressBackground", typeof(Brush), typeof(ToolButton), new PropertyMetadata(new SolidColorBrush(Colors.White)));
48 public static readonly DependencyProperty ProgressBackgroundProperty = DependencyProperty.Register("ProgressBackground", typeof(Brush), typeof(MiniToolButton), new PropertyMetadata(new SolidColorBrush(Colors.White)));
49 49
50 50 public Brush ProgressBorderBrush
51 51 {
52 52 get { return (Brush)GetValue(ProgressBorderBrushProperty); }
53 53 set { SetValue(ProgressBorderBrushProperty, value); }
54 54 }
55 public static readonly DependencyProperty ProgressBorderBrushProperty = DependencyProperty.Register("ProgressBorderBrush", typeof(Brush), typeof(ToolButton), new PropertyMetadata(new SolidColorBrush(Color.FromRgb(255, 151, 88))));
55 public static readonly DependencyProperty ProgressBorderBrushProperty = DependencyProperty.Register("ProgressBorderBrush", typeof(Brush), typeof(MiniToolButton), new PropertyMetadata(new SolidColorBrush(Color.FromRgb(255, 151, 88))));
56 56
57 57 public double ProgressLargeChange
58 58 {
59 59 get { return (double)GetValue(ProgressLargeChangeProperty); }
60 60 set { SetValue(ProgressLargeChangeProperty, value); }
61 61 }
62 public static readonly DependencyProperty ProgressLargeChangeProperty = DependencyProperty.Register("ProgressLargeChange", typeof(double), typeof(ToolButton), new PropertyMetadata(1d));
62 public static readonly DependencyProperty ProgressLargeChangeProperty = DependencyProperty.Register("ProgressLargeChange", typeof(double), typeof(MiniToolButton), new PropertyMetadata(1d));
63 63
64 64 public double ProgressSmallChange
65 65 {
66 66 get { return (double)GetValue(ProgressSmallChangeProperty); }
67 67 set { SetValue(ProgressSmallChangeProperty, value); }
68 68 }
69 public static readonly DependencyProperty ProgressSmallChangeProperty = DependencyProperty.Register("ProgressSmallChange", typeof(double), typeof(ToolButton), new PropertyMetadata(0.1d));
69 public static readonly DependencyProperty ProgressSmallChangeProperty = DependencyProperty.Register("ProgressSmallChange", typeof(double), typeof(MiniToolButton), new PropertyMetadata(0.1d));
70 70
71 71 public double ProgressMaximum
72 72 {
73 73 get { return (double)GetValue(ProgressMaximumProperty); }
74 74 set { SetValue(ProgressMaximumProperty, value); }
75 75 }
76 public static readonly DependencyProperty ProgressMaximumProperty = DependencyProperty.Register("ProgressMaximum", typeof(double), typeof(ToolButton), new PropertyMetadata(100d));
76 public static readonly DependencyProperty ProgressMaximumProperty = DependencyProperty.Register("ProgressMaximum", typeof(double), typeof(MiniToolButton), new PropertyMetadata(100d));
77 77
78 78 public double ProgressMinimum
79 79 {
80 80 get { return (double)GetValue(ProgressMinimumProperty); }
81 81 set { SetValue(ProgressMinimumProperty, value); }
82 82 }
83 public static readonly DependencyProperty ProgressMinimumProperty = DependencyProperty.Register("ProgressMinimum", typeof(double), typeof(ToolButton), new PropertyMetadata(0d));
83 public static readonly DependencyProperty ProgressMinimumProperty = DependencyProperty.Register("ProgressMinimum", typeof(double), typeof(MiniToolButton), new PropertyMetadata(0d));
84 84
85 85 public double ProgressValue
86 86 {
87 87 get { return (double)GetValue(ProgressValueProperty); }
88 88 set { SetValue(ProgressValueProperty, value); }
89 89 }
90 public static readonly DependencyProperty ProgressValueProperty = DependencyProperty.Register("ProgressValue", typeof(double), typeof(ToolButton), new PropertyMetadata(0d));
90 public static readonly DependencyProperty ProgressValueProperty = DependencyProperty.Register("ProgressValue", typeof(double), typeof(MiniToolButton), new PropertyMetadata(0d));
91 91
92 92 public Visibility ProgressVisibility
93 93 {
94 94 get { return (Visibility)GetValue(ProgressVisibilityProperty); }
95 95 set { SetValue(ProgressVisibilityProperty, value); }
96 96 }
97 public static readonly DependencyProperty ProgressVisibilityProperty = DependencyProperty.Register("ProgressVisibility", typeof(Visibility), typeof(ToolButton), new PropertyMetadata(Visibility.Collapsed));
97 public static readonly DependencyProperty ProgressVisibilityProperty = DependencyProperty.Register("ProgressVisibility", typeof(Visibility), typeof(MiniToolButton), new PropertyMetadata(Visibility.Collapsed));
98 98
99 99 public ICommand Command
100 100 {
101 101 get { return (ICommand)GetValue(CommandProperty); }
102 102 set { SetValue(CommandProperty, value); }
103 103 }
104 public static readonly DependencyProperty CommandProperty = DependencyProperty.Register("Command", typeof(ICommand), typeof(ToolButton), new PropertyMetadata(null));
104 public static readonly DependencyProperty CommandProperty = DependencyProperty.Register("Command", typeof(ICommand), typeof(MiniToolButton), new PropertyMetadata(null));
105 105 #endregion
106 106
107 public ToolButton()
107 public MiniToolButton()
108 108 {
109 109 InitializeComponent();
110 110 }
Modified XFEToolBox/Views/Pages/DownloadPage.xaml +1 -1
@@ -16,7 +16,7 @@
16 16 <Style TargetType="ScrollBar" BasedOn="{StaticResource ConsoleScrollBar}"/>
17 17 </ScrollViewer.Resources>
18 18 <WrapPanel>
19 <ctr:ToolButton ToolName="Steam" IconSource="/Resources/Image/steam_logo.png"/>
19 <ctr:MiniToolButton ToolName="Steam" IconSource="/Resources/Image/steam_logo.png"/>
20 20 </WrapPanel>
21 21 </ScrollViewer>
22 22 </Grid>
Modified XFEToolBox/Views/Pages/MainPage.xaml +1 -1
@@ -22,7 +22,7 @@
22 22 <Border Grid.Row="1" Grid.ColumnSpan="2" CornerRadius="15" Background="White" Margin="10">
23 23 <ScrollViewer VerticalScrollBarVisibility="Hidden" HorizontalScrollBarVisibility="Disabled" Padding="5">
24 24 <WrapPanel>
25 <ctr:ToolButton IconSource="/Resources/Image/steam_logo.png"/>
25 <ctr:MiniToolButton IconSource="/Resources/Image/steam_logo.png"/>
26 26 </WrapPanel>
27 27 </ScrollViewer>
28 28 </Border>
Modified XFEToolBox/Views/Pages/SettingPage.xaml.cs +1 -0
@@ -32,6 +32,7 @@ public partial class SettingPage : Page
32 32 ViewModel.CalculateFileSize();
33 33 ViewModel.DownloadDirectory = $"下载目录:{DownloadProfile.DownloadDirectory}";
34 34 });
35 ViewModel.CheckTargetScrollTab(this);
35 36 }
36 37
37 38 private void TextEditor_TextChanged(object sender, TextChangedEventArgs e) => ViewModel.TextChange(sender, e);