From f94abfe7fd9440bc9df60e53288edce0b392033f 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: Fri, 9 Oct 2026 22:46:52 +0800 Subject: [PATCH 001/125] Update README-zh.md --- README-zh.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README-zh.md b/README-zh.md index 672560ab..451d2b68 100644 --- a/README-zh.md +++ b/README-zh.md @@ -138,6 +138,20 @@ xmlns:wd="https://github.com/WPFDevelopersOrg/WPFDevelopers" +---------- +### MapView +[点击观看 Bilibili 视频教程](https://www.bilibili.com/video/BV1bVhf64EL3/) + +---------- +### MarkdownViewer + + + +---------- +### SwitchTheme + + + ---------- ### CircleMenu From 04dd08c3fefd41b83f334803d87866831751406c 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: Fri, 9 Oct 2026 22:46:55 +0800 Subject: [PATCH 002/125] Update README.md --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index 4842bbea..d6d39299 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,23 @@ xmlns:wd="https://github.com/WPFDevelopersOrg/WPFDevelopers" `xmlns:wd="https://github.com/WPFDevelopersOrg/WPFDevelopers"` +---------- +### MapView + + + + + +---------- +### MarkdownViewer + + + +---------- +### SwitchTheme + + + ---------- ### CircleMenu From 9c486fb1a526dee347568dab13962a989d70fbcb 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: Sun, 11 Oct 2026 23:14:20 +0800 Subject: [PATCH 003/125] =?UTF-8?q?Fix=20issue:=20DateRangePicker=20input?= =?UTF-8?q?=20non=20numeric=20program=20crash=20=EF=BC=88#294=EF=BC=89=20?= =?UTF-8?q?=F0=9F=91=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DateRangePicker/DateRangePicker.cs | 77 ++++++++++++++++--- .../Themes/DateRangePicker.xaml | 4 +- 2 files changed, 68 insertions(+), 13 deletions(-) diff --git a/src/WPFDevelopers.Shared/Controls/DateRangePicker/DateRangePicker.cs b/src/WPFDevelopers.Shared/Controls/DateRangePicker/DateRangePicker.cs index 00180594..dd6ab629 100644 --- a/src/WPFDevelopers.Shared/Controls/DateRangePicker/DateRangePicker.cs +++ b/src/WPFDevelopers.Shared/Controls/DateRangePicker/DateRangePicker.cs @@ -514,8 +514,8 @@ private void HandleDateSelection(DateTime clickedDate, bool isStartCalendar) if (clickedDate < _startDate.Value.Date) { - clickedDateTime = clickedDate + startTime; - otherDateTime = _startDate.Value.Date + endTime; + clickedDateTime = clickedDate + startTime; + otherDateTime = _startDate.Value.Date + endTime; _startDate = clickedDateTime; _endDate = otherDateTime; @@ -527,7 +527,7 @@ private void HandleDateSelection(DateTime clickedDate, bool isStartCalendar) } else { - clickedDateTime = clickedDate + endTime; + clickedDateTime = clickedDate + endTime; _endDate = clickedDateTime; if (isStartCalendar) @@ -571,6 +571,7 @@ private void UpdateEndDateFromTextBox() if (string.IsNullOrWhiteSpace(_endTextBox.Text)) { _endDate = null; + EndDate = null; SetIsHighlightFalse(_startCalendarDayButtons); return; } @@ -581,8 +582,17 @@ private void UpdateEndDateFromTextBox() return; if (StartDate.HasValue && dateTime < StartDate.Value.Date) { - EndDate = _endDate; - _endTextBox.Text = _endDate.Value.ToString(DateTimeFormat); + var previousEndDate = _endDate ?? EndDate; + if (previousEndDate.HasValue) + { + EndDate = previousEndDate; + _endTextBox.Text = previousEndDate.Value.ToString(DateTimeFormat); + } + else + { + EndDate = null; + _endTextBox.Text = string.Empty; + } return; } @@ -592,8 +602,17 @@ private void UpdateEndDateFromTextBox() } else { - EndDate = _endDate; - _endTextBox.Text = _endDate.Value.ToString(DateTimeFormat); + var previousEndDate = _endDate ?? EndDate; + if (previousEndDate.HasValue) + { + EndDate = previousEndDate; + _endTextBox.Text = previousEndDate.Value.ToString(DateTimeFormat); + } + else + { + EndDate = null; + _endTextBox.Text = string.Empty; + } } } } @@ -610,6 +629,7 @@ private void UpdateStartDateFromTextBox() if (string.IsNullOrWhiteSpace(_startTextBox.Text)) { _startDate = null; + StartDate = null; SetIsHighlightFalse(_startCalendarDayButtons); return; } @@ -618,10 +638,34 @@ private void UpdateStartDateFromTextBox() { if (StartDate.HasValue && dateTime.ToString(DateTimeFormat) == StartDate.Value.ToString(DateTimeFormat)) return; + if (EndDate.HasValue && dateTime > EndDate.Value.Date) + { + var previousStartDate = _startDate ?? StartDate; + if (previousStartDate.HasValue) + { + StartDate = previousStartDate; + _startTextBox.Text = previousStartDate.Value.ToString(DateTimeFormat); + } + else + { + StartDate = null; + _startTextBox.Text = string.Empty; + } + return; + } if (EndDate.HasValue && dateTime < EndDate.Value.Date) { - StartDate = _startDate; - _startTextBox.Text = _startDate.Value.ToString(DateTimeFormat); + var previousStartDate = _startDate ?? StartDate; + if (previousStartDate.HasValue) + { + StartDate = previousStartDate; + _startTextBox.Text = previousStartDate.Value.ToString(DateTimeFormat); + } + else + { + StartDate = null; + _startTextBox.Text = string.Empty; + } return; } @@ -631,8 +675,17 @@ private void UpdateStartDateFromTextBox() } else { - StartDate = _startDate; - _startTextBox.Text = _startDate.Value.ToString(DateTimeFormat); + var previousStartDate = _startDate ?? StartDate; + if (previousStartDate.HasValue) + { + StartDate = previousStartDate; + _startTextBox.Text = previousStartDate.Value.ToString(DateTimeFormat); + } + else + { + StartDate = null; + _startTextBox.Text = string.Empty; + } } } } @@ -945,4 +998,4 @@ private Button GetButtonFromCalendar(Calendar calendar, bool isNext) return null; } } -} \ No newline at end of file +} diff --git a/src/WPFDevelopers.Shared/Themes/DateRangePicker.xaml b/src/WPFDevelopers.Shared/Themes/DateRangePicker.xaml index 7eae1c94..3a83b4dc 100644 --- a/src/WPFDevelopers.Shared/Themes/DateRangePicker.xaml +++ b/src/WPFDevelopers.Shared/Themes/DateRangePicker.xaml @@ -209,6 +209,7 @@ Background="Transparent" Focusable="True" Foreground="{TemplateBinding Foreground}" + IsReadOnly="True" SelectionBrush="{DynamicResource WD.WindowBorderBrush}" /> + VerticalAlignment="Top" + SelectedItem="{Binding ColorType, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + + + + From 8fd7fcedcb36796b25eabd1d5a280fcd904ae94d 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, 29 Oct 2026 22:57:09 +0800 Subject: [PATCH 095/125] =?UTF-8?q?feat:=20modify=20AboutWindow=20CenterOw?= =?UTF-8?q?ner=20and=20current=20version=20=F0=9F=92=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ExampleViews/AboutWindow.xaml | 19 +++++++++++++------ .../ExampleViews/AboutWindow.xaml.cs | 1 + 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/AboutWindow.xaml b/src/WPFDevelopers.Samples.Shared/ExampleViews/AboutWindow.xaml index 66d97fe3..769d5457 100644 --- a/src/WPFDevelopers.Samples.Shared/ExampleViews/AboutWindow.xaml +++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/AboutWindow.xaml @@ -14,7 +14,7 @@ TitleBackground="{DynamicResource WD.WindowBorderBrush}" TitleBarMode="None" TitleHeight="30" - WindowStartupLocation="CenterScreen" + WindowStartupLocation="CenterOwner" WindowStyle="ToolWindow" mc:Ignorable="d"> @@ -70,12 +70,19 @@ - + VerticalAlignment="Bottom"> + + + Date: Thu, 29 Oct 2026 22:57:25 +0800 Subject: [PATCH 096/125] Update MenuEnum.cs --- src/WPFDevelopers.Samples.Shared/Helpers/MenuEnum.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/WPFDevelopers.Samples.Shared/Helpers/MenuEnum.cs b/src/WPFDevelopers.Samples.Shared/Helpers/MenuEnum.cs index 46b43186..8cd13dc7 100644 --- a/src/WPFDevelopers.Samples.Shared/Helpers/MenuEnum.cs +++ b/src/WPFDevelopers.Samples.Shared/Helpers/MenuEnum.cs @@ -30,7 +30,7 @@ public enum MenuEnum PieSegment, Password, SongWords, - TimeLine, + ActivityFeed, CardCarousel, FocusCarousel, Pagination, @@ -81,7 +81,6 @@ public enum MenuEnum ColorPicker, IPEditBox, TimePicker, - WaterfallPanel, ChartLine, Drap, ChartPie, @@ -105,9 +104,9 @@ public enum MenuEnum Segmented, MarkdownViewer, MapView, - BackToTop, ScrollNavigation, WaterfallPanel, + Timeline, VirtualizingWrapPanel, AcrylicBlur, Theme, From 2e5619cb19e0edc3253122bce96d81d26c3a0fc0 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, 29 Oct 2026 22:57:33 +0800 Subject: [PATCH 097/125] Update MenuNameLocalizer.cs --- src/WPFDevelopers.Samples.Shared/Helpers/MenuNameLocalizer.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/WPFDevelopers.Samples.Shared/Helpers/MenuNameLocalizer.cs b/src/WPFDevelopers.Samples.Shared/Helpers/MenuNameLocalizer.cs index 5c887070..59c86cbd 100644 --- a/src/WPFDevelopers.Samples.Shared/Helpers/MenuNameLocalizer.cs +++ b/src/WPFDevelopers.Samples.Shared/Helpers/MenuNameLocalizer.cs @@ -32,7 +32,8 @@ internal static class MenuNameLocalizer [MenuEnum.PieSegment] = "分段饼图", [MenuEnum.Password] = "密码框", [MenuEnum.SongWords] = "歌词", - [MenuEnum.TimeLine] = "时间轴", + [MenuEnum.Timeline] = "时间轴", + [MenuEnum.ActivityFeed] = "活动记录(示例控件)", [MenuEnum.CardCarousel] = "卡片轮播", [MenuEnum.FocusCarousel] = "聚焦轮播", [MenuEnum.Pagination] = "分页", From 9d16a5d2a11f9842970bd2d7bd36e66b357c0e13 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, 29 Oct 2026 23:02:23 +0800 Subject: [PATCH 098/125] =?UTF-8?q?feat:=20modify=20Toast=20PushDesktop=20?= =?UTF-8?q?Not=20displayed=20on=20the=20current=20screen=20of=20the=20main?= =?UTF-8?q?=20program=20=F0=9F=92=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controls/Toast/ToastExt.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/WPFDevelopers.Shared/Controls/Toast/ToastExt.cs b/src/WPFDevelopers.Shared/Controls/Toast/ToastExt.cs index 17c82736..e4a0deb5 100644 --- a/src/WPFDevelopers.Shared/Controls/Toast/ToastExt.cs +++ b/src/WPFDevelopers.Shared/Controls/Toast/ToastExt.cs @@ -1,5 +1,6 @@ using System; using System.Windows; +using System.Windows.Interop; using System.Windows.Media; using WPFDevelopers.Helpers; @@ -57,6 +58,26 @@ private Rect GetTargetArea(IntPtr windowHandle) IsPosition = false; return WindowHelpers.GetWindowBounds(windowHandle); } + + IsPosition = false; + var mainWindow = Application.Current?.MainWindow; + if (mainWindow != null && mainWindow.IsLoaded) + { + var mainWindowHandle = new WindowInteropHelper(mainWindow).Handle; + if (mainWindowHandle != IntPtr.Zero) + { + var screen = System.Windows.Forms.Screen.FromHandle(mainWindowHandle); + var dpi = Win32.GetDpiForWindow(mainWindowHandle); + var scale = dpi > 0 ? dpi / 96.0 : 1.0; + var workArea = screen.WorkingArea; + return new Rect( + workArea.Left / scale, + workArea.Top / scale, + workArea.Width / scale, + workArea.Height / scale); + } + } + return SystemParameters.WorkArea; } From ef22340a19444167bbda8d145b6fc490a33a4453 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, 29 Oct 2026 23:03:53 +0800 Subject: [PATCH 099/125] Update WPFDevelopers.Shared.projitems --- src/WPFDevelopers.Shared/WPFDevelopers.Shared.projitems | 1 - 1 file changed, 1 deletion(-) diff --git a/src/WPFDevelopers.Shared/WPFDevelopers.Shared.projitems b/src/WPFDevelopers.Shared/WPFDevelopers.Shared.projitems index 923c8d45..65348315 100644 --- a/src/WPFDevelopers.Shared/WPFDevelopers.Shared.projitems +++ b/src/WPFDevelopers.Shared/WPFDevelopers.Shared.projitems @@ -77,7 +77,6 @@ - From 1bb2ef300753a39b67cc7c9acd4ec32b72cd4131 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, 29 Oct 2026 23:04:02 +0800 Subject: [PATCH 100/125] Update WPFDevelopers.Shared.projitems --- src/WPFDevelopers.Shared/WPFDevelopers.Shared.projitems | 1 + 1 file changed, 1 insertion(+) diff --git a/src/WPFDevelopers.Shared/WPFDevelopers.Shared.projitems b/src/WPFDevelopers.Shared/WPFDevelopers.Shared.projitems index 65348315..e63dae0f 100644 --- a/src/WPFDevelopers.Shared/WPFDevelopers.Shared.projitems +++ b/src/WPFDevelopers.Shared/WPFDevelopers.Shared.projitems @@ -24,6 +24,7 @@ + From d5b620fa40f5c51de9501e89fdf711b5516e1bd5 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: Fri, 30 Oct 2026 00:23:53 +0800 Subject: [PATCH 101/125] =?UTF-8?q?feat:=20modify=20ScrollViewerBehavior?= =?UTF-8?q?=20display=20BackToTop=20and=20BackToBottom=20position=20?= =?UTF-8?q?=F0=9F=91=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ScrollViewer/ScrollViewerBehavior.cs | 117 ++++++++++++++++-- 1 file changed, 108 insertions(+), 9 deletions(-) diff --git a/src/WPFDevelopers.Shared/Controls/ScrollViewer/ScrollViewerBehavior.cs b/src/WPFDevelopers.Shared/Controls/ScrollViewer/ScrollViewerBehavior.cs index c275817a..f8ddf691 100644 --- a/src/WPFDevelopers.Shared/Controls/ScrollViewer/ScrollViewerBehavior.cs +++ b/src/WPFDevelopers.Shared/Controls/ScrollViewer/ScrollViewerBehavior.cs @@ -141,6 +141,8 @@ private sealed class BackToTopState private Button _backToBottomButton; private Window _ownerWindow; private readonly DispatcherTimer _hideTimer; + private DispatcherOperation _openOperation; + private DispatcherOperation _revealOperation; public BackToTopState(FrameworkElement target) { @@ -289,6 +291,7 @@ private void Attach() private void Detach() { _hideTimer.Stop(); + CancelPendingPopupOperations(); if (_scrollViewer != null) _scrollViewer.ScrollChanged -= OnScrollChanged; @@ -357,15 +360,13 @@ private void OnOwnerWindowActivated(object sender, EventArgs e) private void OnOwnerWindowDeactivated(object sender, EventArgs e) { _hideTimer.Stop(); - if (_popup != null) - _popup.IsOpen = false; + ClosePopup(); } private void OnOwnerWindowClosed(object sender, EventArgs e) { _hideTimer.Stop(); - if (_popup != null) - _popup.IsOpen = false; + ClosePopup(); } private void OnScrollChanged(object sender, ScrollChangedEventArgs e) @@ -392,7 +393,7 @@ private void UpdateButton() PresentationSource.FromVisual(_target) == null) { _hideTimer.Stop(); - _popup.IsOpen = false; + ClosePopup(); return; } @@ -414,9 +415,7 @@ private void UpdateButton() _backToTopButton.Visibility == Visibility.Visible ? 1 : 0) + (_backToBottomButton != null && _backToBottomButton.Visibility == Visibility.Visible ? 1 : 0); - var panelWidth = visibleButtonCount * 36 + Math.Max(0, visibleButtonCount - 1) * 6; - _popup.HorizontalOffset = Math.Max(0, _target.ActualWidth - panelWidth - 16); - _popup.VerticalOffset = Math.Max(0, _target.ActualHeight - 52); + UpdatePopupOffsets(visibleButtonCount); var isOwnerWindowVisible = _ownerWindow == null || (_ownerWindow.IsVisible && _ownerWindow.IsActive && @@ -427,11 +426,111 @@ private void UpdateButton() visibleButtonCount > 0; if (!shouldOpen) { - _popup.IsOpen = false; + ClosePopup(); return; } + if (!_popup.IsOpen) + ScheduleOpenPopup(); + } + + private void UpdatePopupOffsets(int visibleButtonCount) + { + var panelWidth = visibleButtonCount * 36 + Math.Max(0, visibleButtonCount - 1) * 6; + _popup.HorizontalOffset = Math.Max(0, _target.ActualWidth - panelWidth - 16); + _popup.VerticalOffset = Math.Max(0, _target.ActualHeight - 52); + } + + private void ScheduleOpenPopup() + { + if (_openOperation != null || _revealOperation != null) + return; + + _openOperation = _target.Dispatcher.BeginInvoke( + DispatcherPriority.Loaded, + new Action(OpenPopup)); + } + + private void OpenPopup() + { + _openOperation = null; + if (!CanOpenPopup()) + return; + + var visibleButtonCount = GetVisibleButtonCount(); + UpdatePopupOffsets(visibleButtonCount); + _buttonPanel.Opacity = 0; _popup.IsOpen = true; + + var horizontalOffset = _popup.HorizontalOffset; + _popup.HorizontalOffset = horizontalOffset + 0.1; + _popup.HorizontalOffset = horizontalOffset; + + _revealOperation = _target.Dispatcher.BeginInvoke( + DispatcherPriority.Render, + new Action(RevealPopup)); + } + + private void RevealPopup() + { + _revealOperation = null; + if (!CanOpenPopup() || !_popup.IsOpen) + { + ClosePopup(); + return; + } + + _buttonPanel.Opacity = 1; + } + + private bool CanOpenPopup() + { + var isOwnerWindowVisible = _ownerWindow == null || + (_ownerWindow.IsVisible && + _ownerWindow.IsActive && + _ownerWindow.WindowState != WindowState.Minimized); + return _popup != null && + _buttonPanel != null && + _target.IsLoaded && + _target.IsVisible && + _target.ActualWidth > 0 && + _target.ActualHeight > 0 && + PresentationSource.FromVisual(_target) != null && + isOwnerWindowVisible && + IsInteractionActive() && + GetVisibleButtonCount() > 0; + } + + private int GetVisibleButtonCount() + { + return (_backToTopButton != null && + _backToTopButton.Visibility == Visibility.Visible ? 1 : 0) + + (_backToBottomButton != null && + _backToBottomButton.Visibility == Visibility.Visible ? 1 : 0); + } + + private void ClosePopup() + { + CancelPendingPopupOperations(); + if (_buttonPanel != null) + _buttonPanel.Opacity = 0; + if (_popup != null) + _popup.IsOpen = false; + } + + private void CancelPendingPopupOperations() + { + if (_openOperation != null) + { + _openOperation.Abort(); + _openOperation = null; + } + + if (_revealOperation != null) + { + _revealOperation.Abort(); + _revealOperation = null; + } } private bool IsInteractionActive() From 04133c8e381097d732489ea04f09cb8c3f6f5c6f 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: Fri, 30 Oct 2026 00:27:00 +0800 Subject: [PATCH 102/125] =?UTF-8?q?feat:=20modify=20DateRangelPicker=20Cal?= =?UTF-8?q?endarDayButton=20dispaly=20error=20=F0=9F=91=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DateRangePicker/DateRangePicker.cs | 175 +++++++++--------- 1 file changed, 86 insertions(+), 89 deletions(-) diff --git a/src/WPFDevelopers.Shared/Controls/DateRangePicker/DateRangePicker.cs b/src/WPFDevelopers.Shared/Controls/DateRangePicker/DateRangePicker.cs index ca35e42a..b575957b 100644 --- a/src/WPFDevelopers.Shared/Controls/DateRangePicker/DateRangePicker.cs +++ b/src/WPFDevelopers.Shared/Controls/DateRangePicker/DateRangePicker.cs @@ -159,21 +159,32 @@ public bool HasTimeFormat private static void OnStartDateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { - var ctrl = d as DateRangePicker; - if (ctrl != null && ctrl._startTextBox != null) - { - ctrl._startTextBox.Text = e.NewValue?.ToString(); - ctrl.UpdateStartDateFromTextBox(); - } + var ctrl = (DateRangePicker)d; + ctrl._startDate = (DateTime?)e.NewValue; + ctrl.UpdateDateTextBox(ctrl._startTextBox, ctrl._startDate, ctrl.TextBoxStart_TextChanged); } private static void OnEndDateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { - var ctrl = d as DateRangePicker; - if (ctrl != null && ctrl._endTextBox != null) + var ctrl = (DateRangePicker)d; + ctrl._endDate = (DateTime?)e.NewValue; + ctrl.UpdateDateTextBox(ctrl._endTextBox, ctrl._endDate, ctrl.TextBoxEnd_TextChanged); + } + + private void UpdateDateTextBox(DatePickerTextBox textBox, DateTime? date, + TextChangedEventHandler handler) + { + if (textBox == null) + return; + + textBox.TextChanged -= handler; + try + { + textBox.Text = date.HasValue ? date.Value.ToString(DateTimeFormat) : string.Empty; + } + finally { - ctrl._endTextBox.Text = e.NewValue?.ToString(); - ctrl.UpdateEndDateFromTextBox(); + textBox.TextChanged += handler; } } @@ -218,14 +229,30 @@ private static void OnDateFormatChanged(DependencyObject d, DependencyPropertyCh var ctrl = (DateRangePicker)d; if (ctrl == null) return; ctrl.UpdateTimeFormatDetection(); + ctrl.UpdateDateTextBox(ctrl._startTextBox, ctrl.StartDate, ctrl.TextBoxStart_TextChanged); + ctrl.UpdateDateTextBox(ctrl._endTextBox, ctrl.EndDate, ctrl.TextBoxEnd_TextChanged); } static void OnMinAndMaxChanged(DateRangePicker control) { - control._startCalendar.BlackoutDates.Add(new CalendarDateRange(DateTime.MinValue, control.MinDate.Value.AddDays(-1))); - control._endCalendar.BlackoutDates.Add(new CalendarDateRange(DateTime.MinValue, control.MinDate.Value.AddDays(-1))); - control._startCalendar.BlackoutDates.Add(new CalendarDateRange(control.MaxDate.Value.AddDays(1), DateTime.MaxValue)); - control._endCalendar.BlackoutDates.Add(new CalendarDateRange(control.MaxDate.Value.AddDays(1), DateTime.MaxValue)); + control.UpdateBlackoutDates(control._startCalendar); + control.UpdateBlackoutDates(control._endCalendar); + } + + private void UpdateBlackoutDates(Calendar calendar) + { + if (calendar == null) + return; + + if (calendar.SelectedDates.Any(date => + (MinDate.HasValue && date.Date < MinDate.Value.Date) || + (MaxDate.HasValue && date.Date > MaxDate.Value.Date))) + calendar.SelectedDates.Clear(); + calendar.BlackoutDates.Clear(); + if (MinDate.HasValue && MinDate.Value.Date > DateTime.MinValue.Date) + calendar.BlackoutDates.Add(new CalendarDateRange(DateTime.MinValue, MinDate.Value.Date.AddDays(-1))); + if (MaxDate.HasValue && MaxDate.Value.Date < DateTime.MaxValue.Date) + calendar.BlackoutDates.Add(new CalendarDateRange(MaxDate.Value.Date.AddDays(1), DateTime.MaxValue)); } public override void OnApplyTemplate() @@ -240,8 +267,8 @@ public override void OnApplyTemplate() { _popup.Focusable = true; _popup.PlacementTarget = this; - _popup.Closed += OnPopup_Closed; _popup.Closed -= OnPopup_Closed; + _popup.Closed += OnPopup_Closed; _popup.Opened -= OnPopup_Opened; _popup.Opened += OnPopup_Opened; } @@ -270,20 +297,7 @@ public override void OnApplyTemplate() _endCalendar.PreviewMouseUp += OnEndCalendar_PreviewMouseUp; } - if (_startCalendar != null) - { - if (MinDate != null) - _startCalendar.BlackoutDates.Add(new CalendarDateRange(DateTime.MinValue, MinDate.Value.AddDays(-1))); - if (MaxDate != null) - _startCalendar.BlackoutDates.Add(new CalendarDateRange(MaxDate.Value.AddDays(1), DateTime.MaxValue)); - } - if (_endCalendar != null) - { - if (MinDate != null) - _endCalendar.BlackoutDates.Add(new CalendarDateRange(DateTime.MinValue, MinDate.Value.AddDays(-1))); - if (MaxDate != null) - _endCalendar.BlackoutDates.Add(new CalendarDateRange(MaxDate.Value.AddDays(1), DateTime.MaxValue)); - } + OnMinAndMaxChanged(this); var now = MinDate == null ? DateTime.Now : MinDate.Value; var firstDayOfNextMonth = new DateTime(now.Year, now.Month, 1).AddMonths(1); _startCalendar.DisplayDate = now; @@ -302,13 +316,13 @@ public override void OnApplyTemplate() _endTextBox = (DatePickerTextBox)GetTemplateChild(EndTextBoxTemplateName); if (_endTextBox != null) _endTextBox.TextChanged += TextBoxEnd_TextChanged; - UpdateTimeFormatDetection(); _startTimePicker = (TimePicker)GetTemplateChild(StartTimePickerTemplateName); if (_startTimePicker != null) _startTimePicker.SelectedTimeChanged += OnStartTimePicker_SelectedTimeChanged; _endTimePicker = (TimePicker)GetTemplateChild(EndTimePickerTemplateName); if (_endTimePicker != null) _endTimePicker.SelectedTimeChanged += OnEndTimePicker_SelectedTimeChanged; + UpdateTimeFormatDetection(); Loaded += DateRangePicker_Loaded; _oKButton = (Button)GetTemplateChild(OKButtonTemplateName); if (_oKButton != null) @@ -329,8 +343,8 @@ private void OnCloseButton_Click(object sender, RoutedEventArgs e) public void ClearDates() { - StartDate = null; - EndDate = null; + SetCurrentValue(StartDateProperty, null); + SetCurrentValue(EndDateProperty, null); _startDate = null; _endDate = null; @@ -358,8 +372,8 @@ private void OnCancelButton_Click(object sender, RoutedEventArgs e) private void RestoreBackupDates() { - StartDate = _backupStartDate; - EndDate = _backupEndDate; + SetCurrentValue(StartDateProperty, _backupStartDate); + SetCurrentValue(EndDateProperty, _backupEndDate); _startDate = _backupStartDate; _endDate = _backupEndDate; if (_startTextBox != null && StartDate.HasValue) @@ -435,8 +449,8 @@ private void UpdateTimePickerVisibility() private void OnEndTimePicker_SelectedTimeChanged(object sender, RoutedPropertyChangedEventArgs e) { - if (_isHandlingSelectionChange || !HasTimeFormat || !_endDate.HasValue) return; - var date = _endDate.Value.Date + _endTimePicker.SelectedTime.Value.TimeOfDay; + if (_isHandlingSelectionChange || !HasTimeFormat || !_endDate.HasValue || !e.NewValue.HasValue) return; + var date = _endDate.Value.Date + e.NewValue.Value.TimeOfDay; _endDate = date; SetSelectedDates(); SetDate(); @@ -444,8 +458,8 @@ private void OnEndTimePicker_SelectedTimeChanged(object sender, RoutedPropertyCh private void OnStartTimePicker_SelectedTimeChanged(object sender, RoutedPropertyChangedEventArgs e) { - if (_isHandlingSelectionChange || !HasTimeFormat || !_startDate.HasValue) return; - var date = _startDate.Value.Date + _startTimePicker.SelectedTime.Value.TimeOfDay; + if (_isHandlingSelectionChange || !HasTimeFormat || !_startDate.HasValue || !e.NewValue.HasValue) return; + var date = _startDate.Value.Date + e.NewValue.Value.TimeOfDay; _startDate = date; SetSelectedDates(); SetDate(); @@ -478,8 +492,9 @@ private void OnCalendar_PreviewMouseUp(object sender, MouseButtonEventArgs e, bo { if (e.OriginalSource is FrameworkElement fe) { - var dayButton = ControlsHelper.FindParent(fe); - if (dayButton != null && dayButton.DataContext is DateTime clickedDate) + var dayButton = fe as CalendarDayButton ?? ControlsHelper.FindParent(fe); + if (dayButton != null && dayButton.IsEnabled && !dayButton.IsBlackedOut && + dayButton.DataContext is DateTime clickedDate) { HandleDateSelection(clickedDate, isStartCalendar); } @@ -580,7 +595,7 @@ private void UpdateEndDateFromTextBox() { if (EndDate.HasValue && dateTime.ToString(DateTimeFormat) == EndDate.Value.ToString(DateTimeFormat)) return; - if (StartDate.HasValue && dateTime < StartDate.Value.Date) + if (StartDate.HasValue && dateTime < StartDate.Value) { var previousEndDate = _endDate ?? EndDate; if (previousEndDate.HasValue) @@ -638,22 +653,7 @@ private void UpdateStartDateFromTextBox() { if (StartDate.HasValue && dateTime.ToString(DateTimeFormat) == StartDate.Value.ToString(DateTimeFormat)) return; - if (EndDate.HasValue && dateTime > EndDate.Value.Date) - { - var previousStartDate = _startDate ?? StartDate; - if (previousStartDate.HasValue) - { - StartDate = previousStartDate; - _startTextBox.Text = previousStartDate.Value.ToString(DateTimeFormat); - } - else - { - StartDate = null; - _startTextBox.Text = string.Empty; - } - return; - } - if (EndDate.HasValue && dateTime < EndDate.Value.Date) + if (EndDate.HasValue && dateTime > EndDate.Value) { var previousStartDate = _startDate ?? StartDate; if (previousStartDate.HasValue) @@ -668,7 +668,6 @@ private void UpdateStartDateFromTextBox() } return; } - SetIsHighlightFalse(_startCalendarDayButtons); StartDate = dateTime; PopupOpened(); @@ -692,15 +691,14 @@ private void UpdateStartDateFromTextBox() private void DateRangePicker_Loaded(object sender, RoutedEventArgs e) { - if (_startTextBox != null && StartDate.HasValue) - _startTextBox.Text = StartDate.Value.ToString(DateTimeFormat); - if (_endTextBox != null && EndDate.HasValue) - _endTextBox.Text = EndDate.Value.ToString(DateTimeFormat); + UpdateDateTextBox(_startTextBox, StartDate, TextBoxStart_TextChanged); + UpdateDateTextBox(_endTextBox, EndDate, TextBoxEnd_TextChanged); } private void OnPopup_Closed(object sender, EventArgs e) { - _window.PreviewMouseDown -= OnWindowPreviewMouseDown; + if (_window != null) + _window.PreviewMouseDown -= OnWindowPreviewMouseDown; _startDate = null; _endDate = null; if (_startCalendar != null) _startCalendar.SelectedDate = null; @@ -711,13 +709,14 @@ private void OnPopup_Opened(object sender, EventArgs e) { _backupStartDate = StartDate; _backupEndDate = EndDate; - _window.PreviewMouseDown += OnWindowPreviewMouseDown; + if (_window != null) + _window.PreviewMouseDown += OnWindowPreviewMouseDown; PopupOpened(); } private void OnWindowPreviewMouseDown(object sender, MouseButtonEventArgs e) { - if (!IsMouseOver) + if (!IsMouseOver && (_popup.Child == null || !_popup.Child.IsMouseOver)) { _popup.IsOpen = false; _startDate = null; @@ -814,7 +813,7 @@ private void OnCalendar_PreviewMouseUp(object sender, MouseButtonEventArgs e) private void OnWindow_MouseDown(object sender, MouseButtonEventArgs e) { - if (_popup != null && _popup.IsOpen) + if (_popup != null && _popup.IsOpen && (_popup.Child == null || !_popup.Child.IsMouseOver)) { _popup.IsOpen = false; _startDate = null; @@ -826,19 +825,23 @@ private void OnWindow_MouseDown(object sender, MouseButtonEventArgs e) private void SetDate() { - StartDate = _startDate; - EndDate = _endDate; - if (_startDate.HasValue) - _startTextBox.Text = _startDate.Value.ToString(DateTimeFormat); - if (_endDate.HasValue) - _endTextBox.Text = _endDate.Value.ToString(DateTimeFormat); + var startDate = _startDate; + var endDate = _endDate; + SetCurrentValue(StartDateProperty, startDate); + SetCurrentValue(EndDateProperty, endDate); + UpdateDateTextBox(_startTextBox, startDate, TextBoxStart_TextChanged); + UpdateDateTextBox(_endTextBox, endDate, TextBoxEnd_TextChanged); } private void OnPreviewMouseUp(object sender, MouseButtonEventArgs e) { if (e.ChangedButton != MouseButton.Left) return; - if (e.OriginalSource is Button button) + if (e.OriginalSource is ButtonBase || + (e.OriginalSource is FrameworkElement source && + ControlsHelper.FindParent(source) != null)) + return; + if (_popup != null && _popup.Child != null && _popup.Child.IsMouseOver) return; if (_popup != null && !_popup.IsOpen) _popup.IsOpen = true; @@ -895,29 +898,23 @@ private void SetSelectedDates(DateTime? endDate = null) actualStartDate = actualEndDate; } - try - { - _startCalendar.SelectedDates.AddRange(actualStartDate, actualEndDate); - _endCalendar.SelectedDates.AddRange(actualStartDate, actualEndDate); - SetIsHighlight(actualEndDate); - SetDate(); - } - catch (ArgumentOutOfRangeException) - { - throw; - } - SetIsHighlight(eDate.Value); + _startDate = actualStartDate; + _endDate = actualEndDate; + // Calendar ranges contain days, not the time selected by the time pickers. + _startCalendar.SelectedDates.AddRange(actualStartDate.Date, actualEndDate.Date); + _endCalendar.SelectedDates.AddRange(actualStartDate.Date, actualEndDate.Date); + SetIsHighlight(actualEndDate); SetDate(); } } private DateTime GetBoundedDate(DateTime date) { - if (MinDate.HasValue && date < MinDate.Value) - return MinDate.Value; + if (MinDate.HasValue && date.Date < MinDate.Value.Date) + return MinDate.Value.Date + date.TimeOfDay; - if (MaxDate.HasValue && date > MaxDate.Value) - return MaxDate.Value; + if (MaxDate.HasValue && date.Date > MaxDate.Value.Date) + return MaxDate.Value.Date + date.TimeOfDay; return date; } From a8e935a98ac29fe9dc61c2a2bc8ade2e48a7e308 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: Fri, 30 Oct 2026 00:27:07 +0800 Subject: [PATCH 103/125] Update WPFDevelopers.SamplesCode.csproj --- .../WPFDevelopers.SamplesCode.csproj | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/WPFDevelopers.SamplesCode/WPFDevelopers.SamplesCode.csproj b/src/WPFDevelopers.SamplesCode/WPFDevelopers.SamplesCode.csproj index 99bcbf0c..18af66d1 100644 --- a/src/WPFDevelopers.SamplesCode/WPFDevelopers.SamplesCode.csproj +++ b/src/WPFDevelopers.SamplesCode/WPFDevelopers.SamplesCode.csproj @@ -17,6 +17,8 @@ + + @@ -84,7 +86,7 @@ - + @@ -94,13 +96,16 @@ - + + + + @@ -115,8 +120,8 @@ - - + + @@ -406,8 +411,8 @@ ExampleViews\ScrollViewerAnimationExample.xaml - - ExampleViews\BackToTopExample.xaml + + ExampleViews\ScrollNavigationExample.xaml ExampleViews\ShakeExample.xaml @@ -440,8 +445,8 @@ ExampleViews\TransformLayoutExample.xaml - - ExampleViews\TimeLineExample.xaml + + ExampleViews\ActivityFeedExample.xaml ExampleViews\TransitionPanelExample.xaml @@ -487,8 +492,8 @@ ExampleViews\BreadCrumbBarExample.xaml - - Controls\TimeLine\TimeLine.xaml + + Controls\ActivityFeed\ActivityFeed.xaml Controls\Drawing\Drawing.xaml From c30d53fd88f7b94a28406973b3bc10f4f68216c0 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: Fri, 30 Oct 2026 00:54:26 +0800 Subject: [PATCH 104/125] =?UTF-8?q?feat:=20modify=20Tag=20add=20Badge=20St?= =?UTF-8?q?yle=20and=20TagExample=20=F0=9F=92=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ExampleViews/TagExample.xaml | 72 +++++++++++-------- src/WPFDevelopers.Shared/Controls/Tag/Tag.cs | 28 ++++++++ src/WPFDevelopers.Shared/Themes/Tag.xaml | 55 ++++++++++++++ 3 files changed, 125 insertions(+), 30 deletions(-) diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/TagExample.xaml b/src/WPFDevelopers.Samples.Shared/ExampleViews/TagExample.xaml index 339fe883..a7827eaa 100644 --- a/src/WPFDevelopers.Samples.Shared/ExampleViews/TagExample.xaml +++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/TagExample.xaml @@ -11,36 +11,48 @@ d:DesignWidth="800" mc:Ignorable="d"> - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/WPFDevelopers.Shared/Controls/Tag/Tag.cs b/src/WPFDevelopers.Shared/Controls/Tag/Tag.cs index 1762b874..615436ea 100644 --- a/src/WPFDevelopers.Shared/Controls/Tag/Tag.cs +++ b/src/WPFDevelopers.Shared/Controls/Tag/Tag.cs @@ -1,11 +1,21 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Input; +using System.Windows.Media; namespace WPFDevelopers.Controls { public class Tag : ContentControl { + public static readonly DependencyProperty LabelProperty = + DependencyProperty.Register("Label", typeof(string), typeof(Tag), new PropertyMetadata(null)); + + public static readonly DependencyProperty LabelBackgroundProperty = + DependencyProperty.Register("LabelBackground", typeof(Brush), typeof(Tag), new PropertyMetadata(Brushes.DimGray)); + + public static readonly DependencyProperty LabelForegroundProperty = + DependencyProperty.Register("LabelForeground", typeof(Brush), typeof(Tag), new PropertyMetadata(Brushes.White)); + public static readonly DependencyProperty IsCloseProperty = DependencyProperty.Register("IsClose", typeof(bool), typeof(Tag), new PropertyMetadata(true)); @@ -25,6 +35,24 @@ public bool IsClose set => SetValue(IsCloseProperty, value); } + public string Label + { + get => (string)GetValue(LabelProperty); + set => SetValue(LabelProperty, value); + } + + public Brush LabelBackground + { + get => (Brush)GetValue(LabelBackgroundProperty); + set => SetValue(LabelBackgroundProperty, value); + } + + public Brush LabelForeground + { + get => (Brush)GetValue(LabelForegroundProperty); + set => SetValue(LabelForegroundProperty, value); + } + public static RoutedCommand CloseCommand { get; } diff --git a/src/WPFDevelopers.Shared/Themes/Tag.xaml b/src/WPFDevelopers.Shared/Themes/Tag.xaml index 7f51e0bb..3f4d523f 100644 --- a/src/WPFDevelopers.Shared/Themes/Tag.xaml +++ b/src/WPFDevelopers.Shared/Themes/Tag.xaml @@ -62,5 +62,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/HomeExample.xaml.cs b/src/WPFDevelopers.Samples.Shared/ExampleViews/HomeExample.xaml.cs new file mode 100644 index 00000000..842c67f6 --- /dev/null +++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/HomeExample.xaml.cs @@ -0,0 +1,261 @@ +using System; +using System.ComponentModel; +using System.Diagnostics; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Net; +using System.Runtime.Serialization; +using System.Runtime.Serialization.Json; +using System.Threading; +using System.Windows; +using System.Windows.Controls; +using WPFDevelopers.Controls; +using Tag = WPFDevelopers.Controls.Tag; + +namespace WPFDevelopers.Samples.ExampleViews +{ + public partial class HomeExample : UserControl + { + private CancellationTokenSource _statisticsRequest; + private bool _statisticsLoaded; + private bool _synchronizingTheme; + + public HomeExample() + { + InitializeComponent(); + VersionTag.Content = typeof(Tag).Assembly.GetName().Version.ToString(3); + Loaded += HomeExample_Loaded; + Unloaded += HomeExample_Unloaded; + } + + private void HomeExample_Loaded(object sender, RoutedEventArgs e) + { + WPFDevelopers.Resources.ThemeChanged -= Resources_ThemeChanged; + WPFDevelopers.Resources.ThemeChanged += Resources_ThemeChanged; + SynchronizeTheme(); + if (!_statisticsLoaded) + RefreshStatistics(); + } + + private void HomeExample_Unloaded(object sender, RoutedEventArgs e) + { + WPFDevelopers.Resources.ThemeChanged -= Resources_ThemeChanged; + if (_statisticsRequest == null) + return; + + _statisticsRequest.Cancel(); + _statisticsRequest = null; + RefreshButton.IsEnabled = true; + } + + private void RefreshButton_Click(object sender, RoutedEventArgs e) + { + RefreshStatistics(); + } + + private void RefreshStatistics() + { + if (_statisticsRequest != null) + return; + + var request = new CancellationTokenSource(); + _statisticsRequest = request; + RefreshButton.IsEnabled = false; + StarsTag.Content = DownloadsTag.Content = "加载中"; + StatisticsStatus.Text = "正在读取 GitHub Star 和 NuGet 累计下载量..."; + var worker = new BackgroundWorker(); + worker.DoWork += (sender, e) => + { + var stars = LoadMetric("GitHub", () => + ReadCount(DownloadJson( + "https://api.github.com/repos/WPFDevelopersOrg/WPFDevelopers", request.Token).Stars)); + request.Token.ThrowIfCancellationRequested(); + var downloads = LoadMetric("NuGet", () => + { + var result = DownloadJson( + "https://azuresearch-usnc.nuget.org/query?q=packageid:WPFDevelopers&prerelease=true", request.Token); + var package = result.Data == null ? null : result.Data.FirstOrDefault(item => + string.Equals(item.Id, "WPFDevelopers", StringComparison.OrdinalIgnoreCase)); + if (package == null) + throw new InvalidDataException("NuGet 未返回 WPFDevelopers 包统计"); + return ReadCount(package.TotalDownloads); + }); + e.Result = new[] { stars, downloads }; + }; + worker.RunWorkerCompleted += (sender, e) => + { + var isCurrent = ReferenceEquals(_statisticsRequest, request); + request.Dispose(); + worker.Dispose(); + if (!isCurrent) + return; + + _statisticsRequest = null; + RefreshButton.IsEnabled = true; + if (e.Error != null) + { + StarsTag.Content = DownloadsTag.Content = "加载失败"; + StatisticsStatus.Text = "统计加载失败:" + e.Error.Message + "。请点击“刷新统计”重试。"; + return; + } + + var metrics = (MetricResult[])e.Result; + StarsTag.Content = metrics[0].Content; + DownloadsTag.Content = metrics[1].Content; + var errors = metrics.Where(metric => metric.Error != null).Select(metric => metric.Error).ToArray(); + _statisticsLoaded = errors.Length == 0; + StatisticsStatus.Text = _statisticsLoaded + ? "更新于 " + DateTime.Now.ToString("HH:mm:ss") + " · 下载量为 NuGet 所有版本累计下载量" + : string.Join(Environment.NewLine, errors); + }; + worker.RunWorkerAsync(); + } + + private static MetricResult LoadMetric(string source, Func load) + { + try + { + return new MetricResult { Content = load().ToString("N0", CultureInfo.InvariantCulture) }; + } + catch (WebException ex) + { + return MetricFailure(source, ex); + } + catch (SerializationException ex) + { + return MetricFailure(source, ex); + } + catch (InvalidDataException ex) + { + return MetricFailure(source, ex); + } + } + + private static MetricResult MetricFailure(string source, Exception error) + { + return new MetricResult + { + Content = "加载失败", + Error = source + " 统计加载失败:" + error.Message + "。请点击“刷新统计”重试。" + }; + } + + private static T DownloadJson(string address, CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + var request = (HttpWebRequest)WebRequest.Create(address); + request.UserAgent = "WPFDevelopers-Demo/1.0"; + request.Accept = "application/json"; + request.Timeout = 15000; + request.ReadWriteTimeout = 15000; + using (cancellationToken.Register(request.Abort)) + using (var response = request.GetResponse()) + using (var stream = response.GetResponseStream()) + { + var result = new DataContractJsonSerializer(typeof(T)).ReadObject(stream); + if (result == null) + throw new InvalidDataException("统计响应为空"); + return (T)result; + } + } + + private static long ReadCount(long? count) + { + if (!count.HasValue || count.Value < 0) + throw new InvalidDataException("统计响应缺少有效的计数"); + return count.Value; + } + + private void RepositoryButton_Click(object sender, RoutedEventArgs e) + { + var button = sender as Button; + var address = button == null ? null : button.Tag as string; + Uri uri; + if (!Uri.TryCreate(address, UriKind.Absolute, out uri) || uri.Scheme != Uri.UriSchemeHttps) + throw new InvalidOperationException("Repository button has no valid HTTPS address."); + + try + { + Process.Start(new ProcessStartInfo(uri.AbsoluteUri) { UseShellExecute = true }); + LinkError.Visibility = Visibility.Collapsed; + } + catch (Win32Exception ex) + { + ShowLinkError(ex); + } + catch (InvalidOperationException ex) + { + ShowLinkError(ex); + } + } + + private void ShowLinkError(Exception error) + { + LinkError.Text = "无法打开链接:" + error.Message; + LinkError.Visibility = Visibility.Visible; + } + + private void Segmented_ItemClick(object sender, RoutedEventArgs e) + { + if (_synchronizingTheme) return; + var segmented = sender as Segmented; + var theme = segmented.SelectedIndex == 0 ? ThemeType.Light : ThemeType.Dark; + if (ThemeManager.Instance.Resources.Theme == theme) return; + App.Theme = theme; + ThemeManager.Instance.SwitchTheme(PART_Segmented, theme); + SynchronizeTheme(); + } + + private void Resources_ThemeChanged(ThemeType currentTheme) + { + SynchronizeTheme(); + } + + private void SynchronizeTheme() + { + var theme = ThemeManager.Instance.Resources.Theme; + _synchronizingTheme = true; + try + { + PART_Segmented.SelectedIndex = theme == ThemeType.Dark ? 1 : 0; + SegmentedLight.IsChecked = theme != ThemeType.Dark; + SegmentedDark.IsChecked = theme == ThemeType.Dark; + } + finally + { + _synchronizingTheme = false; + } + } + + private sealed class MetricResult + { + public string Content { get; set; } + public string Error { get; set; } + } + + [DataContract] + private sealed class RepositoryStatistics + { + [DataMember(Name = "stargazers_count")] + public long? Stars { get; set; } + } + + [DataContract] + private sealed class PackageSearchResult + { + [DataMember(Name = "data")] + public PackageStatistics[] Data { get; set; } + } + + [DataContract] + private sealed class PackageStatistics + { + [DataMember(Name = "id")] + public string Id { get; set; } + + [DataMember(Name = "totalDownloads")] + public long? TotalDownloads { get; set; } + } + } +} diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/MainWindow.xaml b/src/WPFDevelopers.Samples.Shared/ExampleViews/MainWindow.xaml index f6f33350..5700d4f3 100644 --- a/src/WPFDevelopers.Samples.Shared/ExampleViews/MainWindow.xaml +++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/MainWindow.xaml @@ -180,16 +180,28 @@ - - - - - - - + + + + + + + + + + diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/MainWindow.xaml.cs b/src/WPFDevelopers.Samples.Shared/ExampleViews/MainWindow.xaml.cs index db684127..af4a8766 100644 --- a/src/WPFDevelopers.Samples.Shared/ExampleViews/MainWindow.xaml.cs +++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/MainWindow.xaml.cs @@ -7,6 +7,7 @@ using System.Windows.Media; using System.Windows.Media.Animation; using WPFDevelopers.Controls; +using WPFDevelopers.Helpers; using WPFDevelopers.Samples.ExampleViews; using WPFDevelopers.Samples.Helpers; using MessageBox = WPFDevelopers.Controls.MessageBox; @@ -34,8 +35,13 @@ private void OnMainWindow_Loaded(object sender, RoutedEventArgs e) private void ThemeSwitchBtn_Click(object sender, RoutedEventArgs e) { - var targetTheme = App.Theme == ThemeType.Dark ? ThemeType.Light : ThemeType.Dark; - ThemeManager.Instance.SwitchTheme(ThemeSwitchBtn, targetTheme); + ToggleTheme(ThemeSwitchBtn); + } + + public void ToggleTheme(FrameworkElement source) + { + var targetTheme = ThemeManager.Instance.Resources.Theme == ThemeType.Dark ? ThemeType.Light : ThemeType.Dark; + ThemeManager.Instance.SwitchTheme(source, targetTheme); App.Theme = targetTheme; SetThemeSource(); ThemeSwitchBtn.IsChecked = targetTheme == ThemeType.Dark; @@ -57,7 +63,7 @@ private void Quit_Click(object sender, RoutedEventArgs e) private void About_Click(object sender, RoutedEventArgs e) { - new AboutWindow().Show(); + new AboutWindow().MaskShowDialog(); } private void SendMessage_Click(object sender, RoutedEventArgs e) { diff --git a/src/WPFDevelopers.Samples.Shared/ViewModels/MainVM.cs b/src/WPFDevelopers.Samples.Shared/ViewModels/MainVM.cs index a2d83b79..4b8bf279 100644 --- a/src/WPFDevelopers.Samples.Shared/ViewModels/MainVM.cs +++ b/src/WPFDevelopers.Samples.Shared/ViewModels/MainVM.cs @@ -137,6 +137,7 @@ public NavigateMenuModel NavigateMenuItem } } private object _controlPanel; + private HomeExample _homePage; private ObservableCollection _customMenuModelList; private ObservableCollection _basicMenuModelList; @@ -234,7 +235,8 @@ public MainVM() var menuModel = new NavigateMenuModel { Name = name, - IsDemo = DemoMenuItems.Contains(menuEnum) + IsDemo = DemoMenuItems.Contains(menuEnum), + IconSource = GetMenuIconSource(menuEnum) }; if (NewMenuItems.Contains(menuEnum)) menuModel.ChangeType = "New"; @@ -255,7 +257,7 @@ public MainVM() }); LanguageManager.Instance.PropertyChanged += LanguageManager_PropertyChanged; UpdateMenuDisplayNames(); - ControlPanel = new NavMenu3DExample(); + ShowHome(); } private static string GetMenuIconSource(MenuEnum menuEnum) @@ -557,9 +559,18 @@ private void UpdateMenuDisplayNames() public ICommand ViewLoaded => new RelayCommand(obj => { + ShowHome(); + }); + public ICommand ShowHomeCommand => new RelayCommand(obj => ShowHome()); - }); + private void ShowHome() + { + NavigateMenuItem = null; + if (_homePage == null) + _homePage = new HomeExample(); + ControlPanel = _homePage; + } public ICommand MenuSearchTextChanged => new RelayCommand(obj => { From 83b278d27206ecd724abaa6fccc3daa59ac465b6 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: Fri, 30 Oct 2026 00:59:46 +0800 Subject: [PATCH 113/125] Update WPFDevelopers.Samples.Shared.projitems --- .../WPFDevelopers.Samples.Shared.projitems | 80 +++++++++++++------ 1 file changed, 55 insertions(+), 25 deletions(-) diff --git a/src/WPFDevelopers.Samples.Shared/WPFDevelopers.Samples.Shared.projitems b/src/WPFDevelopers.Samples.Shared/WPFDevelopers.Samples.Shared.projitems index d63d3623..778eddc2 100644 --- a/src/WPFDevelopers.Samples.Shared/WPFDevelopers.Samples.Shared.projitems +++ b/src/WPFDevelopers.Samples.Shared/WPFDevelopers.Samples.Shared.projitems @@ -8,19 +8,33 @@ WPFDevelopers.Samples + + $(MSBuildThisFileDirectory)app.manifest + + + + HomeExample.xaml + + + MSBuild:Compile + Designer + + + Resources\Assets\wxgzh.jpg + Code App.xaml - - + + - + @@ -36,9 +50,9 @@ - - - + + + @@ -120,9 +134,9 @@ Code BreatheLightExample.xaml - + Code - BubblleControlExample.xaml + BubbleSelectionExample.xaml Code @@ -176,9 +190,9 @@ Code CropAvatarWindow.xaml - + Code - CropControlExample.xaml + ImageCropExample.xaml Code @@ -408,9 +422,9 @@ NumericBoxExample.xaml - + Code - OtherControlExample.xaml + FlameExample.xaml Code @@ -433,9 +447,9 @@ PathIconExample.xaml - + Code - PieControlExample.xaml + PieSegmentExample.xaml Code @@ -449,9 +463,9 @@ Code RoundPickerExample.xaml - + Code - RulerControlExample.xaml + RulerExample.xaml Code @@ -461,6 +475,10 @@ Code ScrollViewerAnimationExample.xaml + + Code + ScrollNavigationExample.xaml + Code SelectorExample.xaml @@ -616,6 +634,9 @@ SliderExample.xaml + + GridSplitterExample.xaml + ProgressBarExample.xaml @@ -653,10 +674,11 @@ + - + MSBuild:Compile Designer @@ -668,7 +690,7 @@ MSBuild:Compile Designer - + MSBuild:Compile Designer @@ -704,11 +726,11 @@ MSBuild:Compile Designer - + MSBuild:Compile Designer - + MSBuild:Compile Designer @@ -800,7 +822,7 @@ MSBuild:Compile Designer - + MSBuild:Compile Designer @@ -856,7 +878,7 @@ MSBuild:Compile Designer - + MSBuild:Compile Designer @@ -1129,7 +1151,7 @@ MSBuild:Compile Designer - + MSBuild:Compile Designer @@ -1153,7 +1175,7 @@ MSBuild:Compile Designer - + MSBuild:Compile Designer @@ -1169,7 +1191,7 @@ MSBuild:Compile Designer - + MSBuild:Compile Designer @@ -1181,6 +1203,10 @@ MSBuild:Compile Designer + + MSBuild:Compile + Designer + MSBuild:Compile Designer @@ -1353,6 +1379,10 @@ MSBuild:Compile Designer + + MSBuild:Compile + Designer + MSBuild:Compile Designer From cebfbcdff1c1ba3366a8387a71f863aecf1de8eb 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: Fri, 30 Oct 2026 01:14:33 +0800 Subject: [PATCH 114/125] =?UTF-8?q?feat:=20Modify=20multi=20screen=20DPI?= =?UTF-8?q?=20display=20blur,=20window=20not=20centered=20screen=20display?= =?UTF-8?q?=20=F0=9F=92=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WindowChromeWorker.cs | 22 +-- src/WPFDevelopers.Net40/Window.cs | 73 +++++---- src/WPFDevelopers.Net45x/Window.cs | 73 +++++---- .../Core/Helpers/WindowStartupHelper.cs | 140 ++++++++++++++++++ 4 files changed, 218 insertions(+), 90 deletions(-) create mode 100644 src/WPFDevelopers.Shared/Core/Helpers/WindowStartupHelper.cs diff --git a/src/Microsoft.Windows.Shell/WindowChromeWorker.cs b/src/Microsoft.Windows.Shell/WindowChromeWorker.cs index ec9b940b..5f0a5d6d 100644 --- a/src/Microsoft.Windows.Shell/WindowChromeWorker.cs +++ b/src/Microsoft.Windows.Shell/WindowChromeWorker.cs @@ -319,13 +319,13 @@ private IntPtr _HandleNCHitTest(WM uMsg, IntPtr wParam, IntPtr lParam, out bool { Point point = new Point((double)Utility.GET_X_LPARAM(lParam), (double)Utility.GET_Y_LPARAM(lParam)); Rect deviceRectangle = this._GetWindowRect(); - HT ht = this._HitTestNca(DpiHelper.DeviceRectToLogical(deviceRectangle), DpiHelper.DevicePixelsToLogical(point)); + Point windowOrigin = this._window.PointFromScreen(deviceRectangle.TopLeft); + Point windowEnd = this._window.PointFromScreen(deviceRectangle.BottomRight); + Point logicalPoint = this._window.PointFromScreen(point); + HT ht = this._HitTestNca(new Rect(windowOrigin, windowEnd), logicalPoint); if (ht != HT.CLIENT) { - Point point2 = point; - point2.Offset(-deviceRectangle.X, -deviceRectangle.Y); - point2 = DpiHelper.DevicePixelsToLogical(point2); - IInputElement inputElement = this._window.InputHitTest(point2); + IInputElement inputElement = this._window.InputHitTest(logicalPoint); if (inputElement != null && WindowChrome.GetIsHitTestVisibleInChrome(inputElement)) { ht = HT.CLIENT; @@ -578,7 +578,7 @@ private void _SetRoundingRegion(WINDOWPOS? wp) try { double num3 = Math.Min(size.Width, size.Height); - double num4 = DpiHelper.LogicalPixelsToDevice(new Point(this._chromeInfo.CornerRadius.TopLeft, 0.0)).X; + double num4 = this._hwndSource.CompositionTarget.TransformToDevice.Transform(new Point(this._chromeInfo.CornerRadius.TopLeft, 0.0)).X; num4 = Math.Min(num4, num3 / 2.0); if (WindowChromeWorker._IsUniform(this._chromeInfo.CornerRadius)) { @@ -587,17 +587,17 @@ private void _SetRoundingRegion(WINDOWPOS? wp) else { intPtr = WindowChromeWorker._CreateRoundRectRgn(new Rect(0.0, 0.0, size.Width / 2.0 + num4, size.Height / 2.0 + num4), num4); - double num5 = DpiHelper.LogicalPixelsToDevice(new Point(this._chromeInfo.CornerRadius.TopRight, 0.0)).X; + double num5 = this._hwndSource.CompositionTarget.TransformToDevice.Transform(new Point(this._chromeInfo.CornerRadius.TopRight, 0.0)).X; num5 = Math.Min(num5, num3 / 2.0); Rect region = new Rect(0.0, 0.0, size.Width / 2.0 + num5, size.Height / 2.0 + num5); region.Offset(size.Width / 2.0 - num5, 0.0); WindowChromeWorker._CreateAndCombineRoundRectRgn(intPtr, region, num5); - double num6 = DpiHelper.LogicalPixelsToDevice(new Point(this._chromeInfo.CornerRadius.BottomLeft, 0.0)).X; + double num6 = this._hwndSource.CompositionTarget.TransformToDevice.Transform(new Point(this._chromeInfo.CornerRadius.BottomLeft, 0.0)).X; num6 = Math.Min(num6, num3 / 2.0); Rect region2 = new Rect(0.0, 0.0, size.Width / 2.0 + num6, size.Height / 2.0 + num6); region2.Offset(0.0, size.Height / 2.0 - num6); WindowChromeWorker._CreateAndCombineRoundRectRgn(intPtr, region2, num6); - double num7 = DpiHelper.LogicalPixelsToDevice(new Point(this._chromeInfo.CornerRadius.BottomRight, 0.0)).X; + double num7 = this._hwndSource.CompositionTarget.TransformToDevice.Transform(new Point(this._chromeInfo.CornerRadius.BottomRight, 0.0)).X; num7 = Math.Min(num7, num3 / 2.0); Rect region3 = new Rect(0.0, 0.0, size.Width / 2.0 + num7, size.Height / 2.0 + num7); region3.Offset(size.Width / 2.0 - num7, size.Height / 2.0 - num7); @@ -661,8 +661,8 @@ private void _ExtendGlassFrame() return; } this._hwndSource.CompositionTarget.BackgroundColor = Colors.Transparent; - Point point = DpiHelper.LogicalPixelsToDevice(new Point(this._chromeInfo.GlassFrameThickness.Left, this._chromeInfo.GlassFrameThickness.Top)); - Point point2 = DpiHelper.LogicalPixelsToDevice(new Point(this._chromeInfo.GlassFrameThickness.Right, this._chromeInfo.GlassFrameThickness.Bottom)); + Point point = this._hwndSource.CompositionTarget.TransformToDevice.Transform(new Point(this._chromeInfo.GlassFrameThickness.Left, this._chromeInfo.GlassFrameThickness.Top)); + Point point2 = this._hwndSource.CompositionTarget.TransformToDevice.Transform(new Point(this._chromeInfo.GlassFrameThickness.Right, this._chromeInfo.GlassFrameThickness.Bottom)); MARGINS margins = new MARGINS { cxLeftWidth = (int)Math.Ceiling(point.X), diff --git a/src/WPFDevelopers.Net40/Window.cs b/src/WPFDevelopers.Net40/Window.cs index 58169eb5..0147a283 100644 --- a/src/WPFDevelopers.Net40/Window.cs +++ b/src/WPFDevelopers.Net40/Window.cs @@ -172,11 +172,19 @@ public object TitleBarLayout set => SetValue(TitleBarLayoutProperty, value); } + protected override void OnInitialized(EventArgs e) + { + base.OnInitialized(e); + if (WindowStartupLocation == WindowStartupLocation.CenterScreen) + WindowStartupHelper.CenterOnCursorMonitor(this); + } + protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); hWnd = new WindowInteropHelper(this).Handle; - HwndSource.FromHwnd(hWnd).AddHook(WindowProc); + var source = HwndSource.FromHwnd(hWnd); + source.AddHook(WindowProc); } protected override void OnContentRendered(EventArgs e) @@ -253,61 +261,40 @@ private IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, re break; #region SnapLayouts case WindowsMessageCodes.WM_NCHITTEST: - try + if (OSVersionHelper.IsSnapLayoutSupported() && ResizeMode != ResizeMode.NoResize && ResizeMode != ResizeMode.CanMinimize) { - if (OSVersionHelper.IsSnapLayoutSupported() && ResizeMode != ResizeMode.NoResize && ResizeMode != ResizeMode.CanMinimize) + var button = TitleBarMode == TitleBarMode.Normal + ? (WindowState != WindowState.Maximized ? _titleBarMaximizeButton : _titleBarRestoreButton) + : (WindowState != WindowState.Maximized ? _highTitleMaximizeButton : _highTitleRestoreButton); + if (button != null) { - int x = lParam.ToInt32() & 0xffff; - int y = lParam.ToInt32() >> 16; - var dpiX = OSVersionHelper.DeviceUnitsScalingFactorX; - var button = TitleBarMode == TitleBarMode.Normal - ? (WindowState != WindowState.Maximized ? _titleBarMaximizeButton : _titleBarRestoreButton) - : (WindowState != WindowState.Maximized ? _highTitleMaximizeButton : _highTitleRestoreButton); - if (button != null) + var contentPresenter = button.Template.FindName("PART_ContentPresenter", button) as ContentPresenter; + if (contentPresenter != null) { - var contentPresenter = button.Template.FindName("PART_ContentPresenter", button) as ContentPresenter; - if (contentPresenter != null) + bool isOverButton = IsPointOverButton(button, lParam); + contentPresenter.Opacity = isOverButton ? 1 : 0.7; + if (isOverButton) { - var rect = new Rect(button.PointToScreen(new Point()), new Size(button.ActualWidth * dpiX, button.ActualHeight * dpiX)); - if (rect.Contains(new Point(x, y))) - { - handled = true; - contentPresenter.Opacity = 1; - } - else - { - contentPresenter.Opacity = 0.7; - } + handled = true; return new IntPtr(OSVersionHelper.HTMAXBUTTON); } - } } } - catch (OverflowException) - { - handled = true; - } break; case WindowsMessageCodes.WM_NCLBUTTONDOWN: if (OSVersionHelper.IsSnapLayoutSupported() && (ResizeMode != ResizeMode.NoResize - || + && ResizeMode != ResizeMode.CanMinimize)) { - int x = lParam.ToInt32() & 0xffff; - int y = lParam.ToInt32() >> 16; - var dpiX = OSVersionHelper.DeviceUnitsScalingFactorX; Button button = TitleBarMode == TitleBarMode.Normal ? (WindowState != WindowState.Maximized ? _titleBarMaximizeButton : _titleBarRestoreButton) : (WindowState != WindowState.Maximized ? _highTitleMaximizeButton : _highTitleRestoreButton); if (button != null) { - var rect = new Rect(button.PointToScreen( - new Point()), - new Size(button.ActualWidth * dpiX, button.ActualHeight * dpiX)); - if (rect.Contains(new Point(x, y))) + if (IsPointOverButton(button, lParam)) { handled = true; IInvokeProvider invokeProv = new ButtonAutomationPeer(button).GetPattern(PatternInterface.Invoke) as IInvokeProvider; @@ -324,17 +311,23 @@ private IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, re return IntPtr.Zero; } + private static bool IsPointOverButton(Button button, IntPtr lParam) + { + long coordinates = lParam.ToInt64(); + var screenPoint = new Point( + unchecked((short)(coordinates & 0xffff)), + unchecked((short)((coordinates >> 16) & 0xffff))); + return new Rect(button.RenderSize).Contains(button.PointFromScreen(screenPoint)); + } + private void ShowSystemMenu(object sender, ExecutedRoutedEventArgs e) { var element = e.OriginalSource as FrameworkElement; if (element == null) return; - var point = WindowState == WindowState.Maximized - ? new Point(0, element.ActualHeight) - : new Point(Left + BorderThickness.Left, element.ActualHeight + Top + BorderThickness.Top); - point = element.TransformToAncestor(this).Transform(point); - SystemCommands.ShowSystemMenu(this, point); + var point = element.PointToScreen(new Point(0, element.ActualHeight)); + SystemCommands.ShowSystemMenuPhysicalCoordinates(this, point); } #endregion diff --git a/src/WPFDevelopers.Net45x/Window.cs b/src/WPFDevelopers.Net45x/Window.cs index f2f724c4..8139d2e6 100644 --- a/src/WPFDevelopers.Net45x/Window.cs +++ b/src/WPFDevelopers.Net45x/Window.cs @@ -179,11 +179,19 @@ private static T GetResourceKey(string key) return resource; return default; } + protected override void OnInitialized(EventArgs e) + { + base.OnInitialized(e); + if (WindowStartupLocation == WindowStartupLocation.CenterScreen) + WindowStartupHelper.CenterOnCursorMonitor(this); + } + protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); hWnd = new WindowInteropHelper(this).Handle; - HwndSource.FromHwnd(hWnd).AddHook(WindowProc); + var source = HwndSource.FromHwnd(hWnd); + source.AddHook(WindowProc); } protected override void OnContentRendered(EventArgs e) @@ -249,61 +257,40 @@ private IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, re break; #region SnapLayouts case WindowsMessageCodes.WM_NCHITTEST: - try + if (OSVersionHelper.IsSnapLayoutSupported() && ResizeMode != ResizeMode.NoResize && ResizeMode != ResizeMode.CanMinimize) { - if (OSVersionHelper.IsSnapLayoutSupported() && ResizeMode != ResizeMode.NoResize && ResizeMode != ResizeMode.CanMinimize) + var button = TitleBarMode == TitleBarMode.Normal + ? (WindowState != WindowState.Maximized ? _titleBarMaximizeButton : _titleBarRestoreButton) + : (WindowState != WindowState.Maximized ? _highTitleMaximizeButton : _highTitleRestoreButton); + if (button != null) { - int x = lParam.ToInt32() & 0xffff; - int y = lParam.ToInt32() >> 16; - var dpiX = OSVersionHelper.DeviceUnitsScalingFactorX; - var button = TitleBarMode == TitleBarMode.Normal - ? (WindowState != WindowState.Maximized ? _titleBarMaximizeButton : _titleBarRestoreButton) - : (WindowState != WindowState.Maximized ? _highTitleMaximizeButton : _highTitleRestoreButton); - if (button != null) + var contentPresenter = button.Template.FindName("PART_ContentPresenter", button) as ContentPresenter; + if (contentPresenter != null) { - var contentPresenter = button.Template.FindName("PART_ContentPresenter", button) as ContentPresenter; - if (contentPresenter != null) + bool isOverButton = IsPointOverButton(button, lParam); + contentPresenter.Opacity = isOverButton ? 1 : 0.7; + if (isOverButton) { - var rect = new Rect(button.PointToScreen(new Point()), new Size(button.ActualWidth * dpiX, button.ActualHeight * dpiX)); - if (rect.Contains(new Point(x, y))) - { - handled = true; - contentPresenter.Opacity = 1; - } - else - { - contentPresenter.Opacity = 0.7; - } + handled = true; return new IntPtr(OSVersionHelper.HTMAXBUTTON); } - } } } - catch (OverflowException) - { - handled = true; - } break; case WindowsMessageCodes.WM_NCLBUTTONDOWN: if (OSVersionHelper.IsSnapLayoutSupported() && (ResizeMode != ResizeMode.NoResize - || + && ResizeMode != ResizeMode.CanMinimize)) { - int x = lParam.ToInt32() & 0xffff; - int y = lParam.ToInt32() >> 16; - var dpiX = OSVersionHelper.DeviceUnitsScalingFactorX; Button button = TitleBarMode == TitleBarMode.Normal ? (WindowState != WindowState.Maximized ? _titleBarMaximizeButton : _titleBarRestoreButton) : (WindowState != WindowState.Maximized ? _highTitleMaximizeButton : _highTitleRestoreButton); if (button != null) { - var rect = new Rect(button.PointToScreen( - new Point()), - new Size(button.ActualWidth * dpiX, button.ActualHeight * dpiX)); - if (rect.Contains(new Point(x, y))) + if (IsPointOverButton(button, lParam)) { handled = true; IInvokeProvider invokeProv = new ButtonAutomationPeer(button).GetPattern(PatternInterface.Invoke) as IInvokeProvider; @@ -322,16 +309,24 @@ private IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, re + private static bool IsPointOverButton(Button button, IntPtr lParam) + { + long coordinates = lParam.ToInt64(); + var screenPoint = new Point( + unchecked((short)(coordinates & 0xffff)), + unchecked((short)((coordinates >> 16) & 0xffff))); + return new Rect(button.RenderSize).Contains(button.PointFromScreen(screenPoint)); + } + private void ShowSystemMenu(object sender, ExecutedRoutedEventArgs e) { var element = e.OriginalSource as FrameworkElement; if (element == null) return; - var point = WindowState == WindowState.Maximized - ? new Point(0, element.ActualHeight) - : new Point(Left + BorderThickness.Left, element.ActualHeight + Top + BorderThickness.Top); - point = element.TransformToAncestor(this).Transform(point); + var screenPoint = element.PointToScreen(new Point(0, element.ActualHeight)); + var source = HwndSource.FromHwnd(hWnd); + var point = source.CompositionTarget.TransformFromDevice.Transform(screenPoint); SystemCommands.ShowSystemMenu(this, point); } diff --git a/src/WPFDevelopers.Shared/Core/Helpers/WindowStartupHelper.cs b/src/WPFDevelopers.Shared/Core/Helpers/WindowStartupHelper.cs new file mode 100644 index 00000000..e1f19cb6 --- /dev/null +++ b/src/WPFDevelopers.Shared/Core/Helpers/WindowStartupHelper.cs @@ -0,0 +1,140 @@ +using System; +using System.ComponentModel; +using System.Runtime.InteropServices; +using System.Windows; +using System.Windows.Interop; +using System.Windows.Threading; + +namespace WPFDevelopers.Helpers +{ + internal static class WindowStartupHelper + { + private const uint MonitorDefaultToNearest = 2; + private const uint SwpNoSize = 0x0001; + private const uint SwpNoZOrder = 0x0004; + private const uint SwpNoActivate = 0x0010; + private const int DwmwaCloak = 13; + + [StructLayout(LayoutKind.Sequential)] + private struct NativePoint + { + public int X; + public int Y; + } + + [StructLayout(LayoutKind.Sequential)] + private struct NativeRect + { + public int Left; + public int Top; + public int Right; + public int Bottom; + } + + [StructLayout(LayoutKind.Sequential)] + private struct MonitorInfo + { + public int Size; + public NativeRect Monitor; + public NativeRect WorkArea; + public uint Flags; + } + + [DllImport("user32.dll", SetLastError = true)] + private static extern bool GetCursorPos(out NativePoint point); + + [DllImport("user32.dll")] + private static extern IntPtr MonitorFromPoint(NativePoint point, uint flags); + + [DllImport("user32.dll", EntryPoint = "GetMonitorInfo", CharSet = CharSet.Auto, SetLastError = true)] + private static extern bool GetMonitorInfo(IntPtr monitor, ref MonitorInfo info); + + [DllImport("user32.dll", SetLastError = true)] + private static extern bool GetWindowRect(IntPtr window, out NativeRect rect); + + [DllImport("user32.dll", SetLastError = true)] + private static extern bool SetWindowPos(IntPtr window, IntPtr insertAfter, int x, int y, int width, int height, uint flags); + + [DllImport("dwmapi.dll", PreserveSig = false)] + private static extern void DwmSetWindowAttribute(IntPtr window, int attribute, ref int value, int size); + + internal static void CenterOnCursorMonitor(Window window) + { + NativePoint cursorPosition; + if (!GetCursorPos(out cursorPosition)) + throw new Win32Exception(Marshal.GetLastWin32Error()); + + var monitor = MonitorFromPoint(cursorPosition, MonitorDefaultToNearest); + var monitorInfo = new MonitorInfo { Size = Marshal.SizeOf(typeof(MonitorInfo)) }; + if (monitor == IntPtr.Zero || !GetMonitorInfo(monitor, ref monitorInfo)) + throw new Win32Exception(Marshal.GetLastWin32Error()); + + var originalOpacity = window.Opacity; + bool useCloak = Environment.OSVersion.Version >= new Version(6, 2); + EventHandler sourceInitialized = null; + if (useCloak) + { + sourceInitialized = delegate + { + window.SourceInitialized -= sourceInitialized; + int cloak = 1; + DwmSetWindowAttribute(new WindowInteropHelper(window).Handle, DwmwaCloak, ref cloak, sizeof(int)); + }; + window.SourceInitialized += sourceInitialized; + } + else + { + window.Opacity = 0; + } + bool completed = false; + EventHandler contentRendered = null; + RoutedEventHandler loaded = null; + Action completeStartup = delegate + { + if (completed) + return; + completed = true; + window.ContentRendered -= contentRendered; + window.Loaded -= loaded; + try + { + var handle = new WindowInteropHelper(window).Handle; + NativeRect windowRect; + if (!GetWindowRect(handle, out windowRect)) + throw new Win32Exception(Marshal.GetLastWin32Error()); + + var width = windowRect.Right - windowRect.Left; + var height = windowRect.Bottom - windowRect.Top; + if (width <= 0 || height <= 0) + throw new InvalidOperationException("The window has no size after its content was rendered."); + + var x = monitorInfo.WorkArea.Left + ((monitorInfo.WorkArea.Right - monitorInfo.WorkArea.Left) - width) / 2; + var y = monitorInfo.WorkArea.Top + ((monitorInfo.WorkArea.Bottom - monitorInfo.WorkArea.Top) - height) / 2; + if (!SetWindowPos(handle, IntPtr.Zero, x, y, 0, 0, + SwpNoSize | SwpNoZOrder | SwpNoActivate)) + throw new Win32Exception(Marshal.GetLastWin32Error()); + } + finally + { + if (useCloak) + { + int cloak = 0; + DwmSetWindowAttribute(new WindowInteropHelper(window).Handle, DwmwaCloak, ref cloak, sizeof(int)); + } + else + { + window.Opacity = originalOpacity; + } + } + }; + contentRendered = delegate { completeStartup(); }; + loaded = delegate + { + if (window.Content == null) + window.Dispatcher.BeginInvoke(DispatcherPriority.ContextIdle, completeStartup); + }; + window.ContentRendered += contentRendered; + window.Loaded += loaded; + } + } +} From a2eb25a65dd994bb1f059ed802b556425d1c6571 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: Fri, 30 Oct 2026 01:14:41 +0800 Subject: [PATCH 115/125] Update Resources.props --- src/Resources.props | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Resources.props b/src/Resources.props index b41fbb04..7fdeed8c 100644 --- a/src/Resources.props +++ b/src/Resources.props @@ -80,6 +80,9 @@ Resources\Svg\%(Filename)%(Extension) + + Resources\MenuIcons\%(Filename)%(Extension) + WPFDevelopers.Samples From ac73a5548fbaf0283f54647428d5b8bbf2b48d95 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: Fri, 30 Oct 2026 01:14:50 +0800 Subject: [PATCH 116/125] Update WPFDevelopers.Shared.projitems --- .../WPFDevelopers.Shared.projitems | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/WPFDevelopers.Shared/WPFDevelopers.Shared.projitems b/src/WPFDevelopers.Shared/WPFDevelopers.Shared.projitems index e63dae0f..b4465888 100644 --- a/src/WPFDevelopers.Shared/WPFDevelopers.Shared.projitems +++ b/src/WPFDevelopers.Shared/WPFDevelopers.Shared.projitems @@ -78,6 +78,9 @@ + + + @@ -238,6 +241,7 @@ + @@ -591,6 +595,11 @@ Designer + MSBuild:Compile + + + MSBuild:Compile + Designer Designer @@ -697,4 +706,4 @@ - + \ No newline at end of file From 9dad84d0d79ca89433c68ffd51d6b34e129784f0 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: Fri, 30 Oct 2026 01:15:02 +0800 Subject: [PATCH 117/125] Update Theme.xaml --- src/WPFDevelopers.Net40/Themes/Theme.xaml | 473 ++++++++++++++++++++-- 1 file changed, 448 insertions(+), 25 deletions(-) diff --git a/src/WPFDevelopers.Net40/Themes/Theme.xaml b/src/WPFDevelopers.Net40/Themes/Theme.xaml index db40b038..20177e00 100644 --- a/src/WPFDevelopers.Net40/Themes/Theme.xaml +++ b/src/WPFDevelopers.Net40/Themes/Theme.xaml @@ -56,6 +56,7 @@ M0.99999994,0.99999994 L0.99999994,9 9,9 9,0.99999994 z M0,0 L10,0 10,10 0,10 z M1,3 L1,9 7,9 7,3 z M3,0.99999994 L3,2 8,2 8,7 9,7 9,0.99999994 z M2,0 L10,0 10,8 8,8 8,10 0,10 0,2 2,2 z M 1301 69.6875 L 1305.3049 74 L 1300.9375 78.5313 L 1301.6324 79.2263 L 1306 74.735 L 1310.4263 79.2613 L 1311.1563 78.5313 L 1306.7 74 L 1310.9375 69.6875 L 1310.2075 68.9575 L 1306 73.265 L 1301.6949 68.9925 L 1301 69.6875 Z + M10,31 C10,31 1.8,21.6 1.8,13.2 C1.8,7.1 5.3,3.2 10,3.2 C14.7,3.2 18.2,7.1 18.2,13.2 C18.2,21.6 10,31 10,31 Z M 426 726 L 810 342 L 750 280 L 426 666 L 274 514 L 214 574 Z M 512 86 C 748 86 938 276 938 512 C 938 748 748 938 512 938 C 276 938 86 748 86 512 C 86 276 276 86 512 86 Z M512 960c-281.6 0-512-230.4-512-512s230.4-512 512-512 512 230.4 512 512-230.4 512-512 512zM576 128h-128v128h128v-128zM576 320h-128v448h128v-448z M512 960c-281.6 0-512-230.4-512-512s230.4-512 512-512 512 230.4 512 512-230.4 512-512 512zM576 128h-128v448h128v-448zM576 640h-128v128h128v-128z @@ -101,6 +102,11 @@ M13 2h-1v1.5c0 .28-.22.5-.5.5h-2c-.28 0-.5-.22-.5-.5V2H6v1.5c0 .28-.22.5-.5.5h-2c-.28 0-.5-.22-.5-.5V2H2c-.55 0-1 .45-1 1v11c0 .55.45 1 1 1h11c.55 0 1-.45 1-1V3c0-.55-.45-1-1-1zm0 12H2V5h11v9zM5 3H4V1h1v2zm6 0h-1V1h1v2zM6 7H5V6h1v1zm2 0H7V6h1v1zm2 0H9V6h1v1zm2 0h-1V6h1v1zM4 9H3V8h1v1zm2 0H5V8h1v1zm2 0H7V8h1v1zm2 0H9V8h1v1zm2 0h-1V8h1v1zm-8 2H3v-1h1v1zm2 0H5v-1h1v1zm2 0H7v-1h1v1zm2 0H9v-1h1v1zm2 0h-1v-1h1v1zm-8 2H3v-1h1v1zm2 0H5v-1h1v1zm2 0H7v-1h1v1zm2 0H9v-1h1v1z M20 109.9988C20 93.43 33.4314 79.998 50 79.998H80L80 99.998H50C44.4772 99.998 40 104.476 40 109.9988L40 249.9988C40 255.5216 44.4772 259.9988 50 259.9988L190 259.9988C195.5228 259.9988 200 255.5216 200 249.9988V219.9996H110C93.4316 219.9996 80 206.5682 80 189.9996V50C80 33.432 93.4316 20 110 20H250C266.568 20 280 33.432 280 50V189.9996C280 206.5682 266.568 219.9996 250 219.9996H220V249.9988C220 266.5674 206.568 279.9988 190 279.9988H50C33.4314 279.9988 20 266.5674 20 249.9988V109.9988zM100 189.9996C100 195.5224 104.4772 199.9996 110 199.9996H250C255.522 199.9996 260 195.5224 260 189.9996V50C260 44.476 255.522 40 250 40H110C104.4772 40 100 44.476 100 50V189.9996z M0,0 L10,0 L6,5 L6,10 L4,10 L4,5 L0,0 + M396 712 L233 512 L178 580 L396 848 L861 272 L807 204 Z + M 1,7 A 6,6 0 0 0 13,7 + M854,346 512,0 170,346 232,404 470,166 470,684 554,684 554,166 794,404z + M170,678 512,1024 854,678 792,620 554,858 554,340 470,340 470,858 232,620z + M1.5,0 A1.5,1.5 0 1 1 1.5,3 A1.5,1.5 0 1 1 1.5,0 Z M1.5,6 A1.5,1.5 0 1 1 1.5,9 A1.5,1.5 0 1 1 1.5,6 Z M1.5,12 A1.5,1.5 0 1 1 1.5,15 A1.5,1.5 0 1 1 1.5,12 Z @@ -368,6 +374,21 @@ + + + + + + + + + + + + + + + @@ -1202,8 +1223,18 @@ - + + + + + + + + + + + @@ -1215,8 +1246,18 @@ - + + + + + + + + + + + @@ -1740,7 +1781,7 @@ + + + + + + - - + + + + + + + + + @@ -6567,6 +6832,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1204,8 +1225,18 @@ - + + + + + + + + + + + @@ -1217,8 +1248,18 @@ - + + + + + + + + + + + @@ -1742,7 +1783,7 @@ + + + + + + - - + + + + + + + + + @@ -6599,6 +6864,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +