From f7c7442dce3be66b244f014da0d22f7371ce6752 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=97=AB=E9=A9=9A=E9=8F=B5=EF=BC=88Jinhua=20Yan=EF=BC=89?= Date: Mon, 2 Nov 2026 01:01:55 +0800 Subject: [PATCH 01/37] feat: fix ScrollViewer MouseWheel unable to scroll --- .../Controls/Timeline/Timeline.cs | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/src/WPFDevelopers.Shared/Controls/Timeline/Timeline.cs b/src/WPFDevelopers.Shared/Controls/Timeline/Timeline.cs index 8220cdb2..5accbf49 100644 --- a/src/WPFDevelopers.Shared/Controls/Timeline/Timeline.cs +++ b/src/WPFDevelopers.Shared/Controls/Timeline/Timeline.cs @@ -3,6 +3,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Input; +using System.Windows.Interop; using System.Windows.Media; namespace WPFDevelopers.Controls @@ -25,7 +26,9 @@ public enum TimelineItemPosition public class Timeline : ItemsControl { private const string ScrollViewerPartName = "PART_ScrollViewer"; + private const int MouseHorizontalWheelMessage = 0x020E; private ScrollViewer _scrollViewer; + private HwndSource _hwndSource; public static readonly DependencyProperty OrientationProperty = DependencyProperty.Register("Orientation", typeof(Orientation), typeof(Timeline), @@ -58,6 +61,12 @@ static Timeline() DefaultStyleKeyProperty.OverrideMetadata(typeof(Timeline), new FrameworkPropertyMetadata(typeof(Timeline))); } + public Timeline() + { + Loaded += OnTimelineLoaded; + Unloaded += OnTimelineUnloaded; + } + public Orientation Orientation { get { return (Orientation)GetValue(OrientationProperty); } @@ -106,9 +115,73 @@ public override void OnApplyTemplate() _scrollViewer.PreviewMouseWheel += OnScrollViewerPreviewMouseWheel; } + private void OnTimelineLoaded(object sender, RoutedEventArgs e) + { + var hwndSource = PresentationSource.FromVisual(this) as HwndSource; + if (ReferenceEquals(_hwndSource, hwndSource)) + return; + if (_hwndSource != null) + _hwndSource.RemoveHook(OnWindowMessage); + _hwndSource = hwndSource; + if (_hwndSource != null) + _hwndSource.AddHook(OnWindowMessage); + } + + private void OnTimelineUnloaded(object sender, RoutedEventArgs e) + { + if (_hwndSource != null) + { + _hwndSource.RemoveHook(OnWindowMessage); + _hwndSource = null; + } + } + + private IntPtr OnWindowMessage(IntPtr hwnd, int message, IntPtr wParam, IntPtr lParam, ref bool handled) + { + if (message != MouseHorizontalWheelMessage || _scrollViewer == null || + Orientation != Orientation.Horizontal || !_scrollViewer.IsVisible) + return IntPtr.Zero; + + var delta = unchecked((short)((long)wParam >> 16)); + if (delta == 0 || _scrollViewer.ScrollableWidth <= 0) + return IntPtr.Zero; + + var screenPoint = new Point( + unchecked((short)(long)lParam), + unchecked((short)((long)lParam >> 16))); + var point = _scrollViewer.PointFromScreen(screenPoint); + if (point.X < 0 || point.Y < 0 || + point.X > _scrollViewer.ActualWidth || point.Y > _scrollViewer.ActualHeight) + return IntPtr.Zero; + + var currentOffset = _scrollViewer.HorizontalOffset; + var targetOffset = Math.Max(0, Math.Min(currentOffset + delta, _scrollViewer.ScrollableWidth)); + if (targetOffset == currentOffset) + return IntPtr.Zero; + + _scrollViewer.ScrollToHorizontalOffset(targetOffset); + handled = true; + return IntPtr.Zero; + } + private void OnScrollViewerPreviewMouseWheel(object sender, MouseWheelEventArgs e) { if (e.Handled || e.Delta == 0) return; + if (Orientation == Orientation.Horizontal && + _scrollViewer.HorizontalScrollBarVisibility != ScrollBarVisibility.Disabled) + { + var canScrollHorizontally = e.Delta > 0 + ? _scrollViewer.HorizontalOffset > 0 + : _scrollViewer.HorizontalOffset < _scrollViewer.ScrollableWidth; + if (canScrollHorizontally) + { + e.Handled = true; + _scrollViewer.ScrollToHorizontalOffset( + _scrollViewer.HorizontalOffset - e.Delta); + return; + } + } + var canScroll = _scrollViewer.VerticalScrollBarVisibility != ScrollBarVisibility.Disabled && (e.Delta > 0 ? _scrollViewer.VerticalOffset > 0 : _scrollViewer.VerticalOffset < _scrollViewer.ScrollableHeight); From 544eba77febda2789e17f73b6fd3599924cf220a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=97=AB=E9=A9=9A=E9=8F=B5=EF=BC=88Jinhua=20Yan=EF=BC=89?= Date: Thu, 5 Nov 2026 00:15:21 +0800 Subject: [PATCH 02/37] =?UTF-8?q?feat:=20modify=20window=20add=20TitleBarL?= =?UTF-8?q?ayout=20sample=20=F0=9F=92=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Window/HighTitleBarWindow.xaml | 29 +++++++- .../Window/HighTitleBarWindow.xaml.cs | 14 +++- .../ExampleViews/Window/NormalWindow.xaml | 29 +++++++- .../ExampleViews/Window/NormalWindow.xaml.cs | 14 +++- .../ExampleViews/Window/WindowExample.xaml | 69 ++++++++++--------- 5 files changed, 120 insertions(+), 35 deletions(-) diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/Window/HighTitleBarWindow.xaml b/src/WPFDevelopers.Samples.Shared/ExampleViews/Window/HighTitleBarWindow.xaml index b281aa06..18181e56 100644 --- a/src/WPFDevelopers.Samples.Shared/ExampleViews/Window/HighTitleBarWindow.xaml +++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/Window/HighTitleBarWindow.xaml @@ -14,12 +14,39 @@ TitleBarMode="High" WindowStartupLocation="CenterScreen" mc:Ignorable="d"> + + + + + + + + + + + + + + + Text="TitleBarLayout: Light / Dark" /> diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/Window/HighTitleBarWindow.xaml.cs b/src/WPFDevelopers.Samples.Shared/ExampleViews/Window/HighTitleBarWindow.xaml.cs index 400e2d6e..5f6474b5 100644 --- a/src/WPFDevelopers.Samples.Shared/ExampleViews/Window/HighTitleBarWindow.xaml.cs +++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/Window/HighTitleBarWindow.xaml.cs @@ -1,4 +1,6 @@ -namespace WPFDevelopers.Samples.ExampleViews +using System.Windows; + +namespace WPFDevelopers.Samples.ExampleViews { /// /// HighTitleBarWindow.xaml 的交互逻辑 @@ -8,6 +10,16 @@ public partial class HighTitleBarWindow public HighTitleBarWindow() { InitializeComponent(); + ThemeSwitchBtn.IsChecked = ThemeManager.Instance.Resources.IsDarkTheme; + Activated += (sender, e) => ThemeSwitchBtn.IsChecked = ThemeManager.Instance.Resources.IsDarkTheme; + } + + private void ThemeSwitchBtn_Click(object sender, RoutedEventArgs e) + { + var targetTheme = ThemeManager.Instance.Resources.IsDarkTheme ? ThemeType.Light : ThemeType.Dark; + ThemeManager.Instance.SwitchTheme(ThemeSwitchBtn, targetTheme); + App.Theme = ThemeManager.Instance.Resources.Theme; + ThemeSwitchBtn.IsChecked = ThemeManager.Instance.Resources.IsDarkTheme; } } } \ No newline at end of file diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/Window/NormalWindow.xaml b/src/WPFDevelopers.Samples.Shared/ExampleViews/Window/NormalWindow.xaml index 65cd4871..cc975fbe 100644 --- a/src/WPFDevelopers.Samples.Shared/ExampleViews/Window/NormalWindow.xaml +++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/Window/NormalWindow.xaml @@ -12,12 +12,39 @@ Icon="pack://application:,,,/WPFDevelopers.Samples;component/WPFDevelopers.ico" WindowStartupLocation="CenterScreen" mc:Ignorable="d"> + + + + + + + + + + + + + + + Text="TitleBarLayout: Light / Dark" /> diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/Window/NormalWindow.xaml.cs b/src/WPFDevelopers.Samples.Shared/ExampleViews/Window/NormalWindow.xaml.cs index 5673fc64..cd27cf4c 100644 --- a/src/WPFDevelopers.Samples.Shared/ExampleViews/Window/NormalWindow.xaml.cs +++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/Window/NormalWindow.xaml.cs @@ -1,4 +1,6 @@  +using System.Windows; + namespace WPFDevelopers.Samples.ExampleViews { /// @@ -9,6 +11,16 @@ public partial class NormalWindow public NormalWindow() { InitializeComponent(); - } + ThemeSwitchBtn.IsChecked = ThemeManager.Instance.Resources.IsDarkTheme; + Activated += (sender, e) => ThemeSwitchBtn.IsChecked = ThemeManager.Instance.Resources.IsDarkTheme; + } + + private void ThemeSwitchBtn_Click(object sender, RoutedEventArgs e) + { + var targetTheme = ThemeManager.Instance.Resources.IsDarkTheme ? ThemeType.Light : ThemeType.Dark; + ThemeManager.Instance.SwitchTheme(ThemeSwitchBtn, targetTheme); + App.Theme = ThemeManager.Instance.Resources.Theme; + ThemeSwitchBtn.IsChecked = ThemeManager.Instance.Resources.IsDarkTheme; + } } } \ No newline at end of file diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/Window/WindowExample.xaml b/src/WPFDevelopers.Samples.Shared/ExampleViews/Window/WindowExample.xaml index 9dc82f30..820634ea 100644 --- a/src/WPFDevelopers.Samples.Shared/ExampleViews/Window/WindowExample.xaml +++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/Window/WindowExample.xaml @@ -12,39 +12,46 @@ mc:Ignorable="d"> - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + - - + + - - - + + + + + + + - - @@ -319,12 +195,10 @@ - - - + diff --git a/src/WPFDevelopers.Net45x/Themes/Theme.xaml b/src/WPFDevelopers.Net45x/Themes/Theme.xaml index c7b39b33..a9cb8927 100644 --- a/src/WPFDevelopers.Net45x/Themes/Theme.xaml +++ b/src/WPFDevelopers.Net45x/Themes/Theme.xaml @@ -35,6 +35,9 @@ Normal Normal M384 690l452-452 60 60-512 512-238-238 60-60z + M12 2a10 10 0 1 0 10 10A7 7 0 0 1 12 2Z + M2 5H7 M11 5H22 M2 12H13 M17 12H22 M2 19H5 M9 19H22 M9 3A2 2 0 1 1 9 7A2 2 0 1 1 9 3 M15 10A2 2 0 1 1 15 14A2 2 0 1 1 15 10 M7 17A2 2 0 1 1 7 21A2 2 0 1 1 7 17 + M12 19a7 7 0 1 1 0-14 7 7 0 0 1 0 14Zm0-1.5a5.5 5.5 0 1 0 0-11 5.5 5.5 0 1 0 0 11Zm-5.657.157a.75.75 0 0 1 0 1.06l-1.768 1.768a.749.749 0 0 1-1.275-.326.749.749 0 0 1 .215-.734l1.767-1.768a.75.75 0 0 1 1.061 0ZM3.515 3.515a.75.75 0 0 1 1.06 0l1.768 1.768a.749.749 0 0 1-.326 1.275.749.749 0 0 1-.734-.215L3.515 4.575a.75.75 0 0 1 0-1.06ZM12 0a.75.75 0 0 1 .75.75v2.5a.75.75 0 0 1-1.5 0V.75A.75.75 0 0 1 12 0ZM4 12a.75.75 0 0 1-.75.75H.75a.75.75 0 0 1 0-1.5h2.5A.75.75 0 0 1 4 12Zm8 8a.75.75 0 0 1 .75.75v2.5a.75.75 0 0 1-1.5 0v-2.5A.75.75 0 0 1 12 20Zm12-8a.75.75 0 0 1-.75.75h-2.5a.75.75 0 0 1 0-1.5h2.5A.75.75 0 0 1 24 12Zm-6.343 5.657a.75.75 0 0 1 1.06 0l1.768 1.768a.751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018l-1.768-1.767a.75.75 0 0 1 0-1.061Zm2.828-14.142a.75.75 0 0 1 0 1.06l-1.768 1.768a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042l1.767-1.768a.75.75 0 0 1 1.061 0Z M 998 352 C 998 344 994 335 988 329 L 938 279 C 932 273 924 269 915 269 C 907 269 898 273 892 279 L 499 672 L 106 279 C 100 273 91 269 83 269 C 75 269 66 273 60 279 L 10 329 C 4 335 0 344 0 352 C 0 360 4 369 10 375 L 476 841 C 482 847 491 851 499 851 C 507 851 516 847 522 841 L 988 375 C 994 369 998 360 998 352 Z M8.1772461,11.029181 L10.433105, @@ -146,6 +149,7 @@ + @@ -685,36 +689,102 @@ - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - + @@ -920,15 +855,15 @@ - - - + + + + - - - + + @@ -938,7 +873,7 @@ - + @@ -950,7 +885,7 @@ - + @@ -974,21 +909,23 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + @@ -1005,28 +942,33 @@ - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1325,7 +1267,7 @@ - + @@ -1443,6 +1385,8 @@ + +