diff --git a/README-zh.md b/README-zh.md
index 451d2b68..3d33005d 100644
--- a/README-zh.md
+++ b/README-zh.md
@@ -1,3 +1,65 @@
+
+
+## 项目简介
+
+WPFDevelopers 为 WPF 项目提供常用控件、统一主题和丰富的交互示例。项目覆盖 .NET Framework 4.0 至 .NET 10;各目标框架与环境要求请查看[快速开始文档](docs/zh/getting-started.md)。
+
+| 主题与样式 | 常用控件 | 示例与扩展 |
+| --- | --- | --- |
+| Light / Dark 主题及主题色配置 | 按钮、输入、导航、图表、窗口等控件 | 配套示例项目,便于查看实现与组合方式 |
+
+## 快速开始
+
+从 NuGet 安装稳定版:
+
+```powershell
+Install-Package WPFDevelopers
+```
+
+体验最新功能可安装预览版:
+
+```powershell
+Install-Package WPFDevelopers -Pre
+```
+
+随后按[快速开始文档](docs/zh/getting-started.md)配置 `App.xaml`,并查看主题选项、控件用法和环境说明。
+
+## 文档与资源
+
+- [快速开始与 .NET 支持范围](docs/zh/getting-started.md)
+- [MapView 地图控件指南](docs/zh/mapview.md)
+- [示例项目源码](src/WPFDevelopers.Samples.Shared/ExampleViews/)
+- [GitHub 仓库](https://github.com/WPFDevelopersOrg/WPFDevelopers) · [AtomGit](https://atomgit.com/WPFDevelopersOrg/WPFDevelopers) · [Gitee](https://gitee.com/WPFDevelopersOrg/WPFDevelopers)
+
+## 控件预览
+
+
+
+完整控件与效果示例仍保留在下方图集中。示例中标注为 `DEMO` 的内容可能是示例专属实现或组合效果,不一定是库内置控件,请以对应源码为准。
+
+
+展开完整示例图集及社区信息
+
[English](https://github.com/WPFDevelopersOrg/WPFDevelopers/blob/master/README.md)
@@ -6,15 +68,13 @@
- [](https://github.com/yanjinhuagood/WPFDevelopers/stargazers) [](https://atomgit.com/WPFDevelopersOrg/WPFDevelopers)
-
-
+ [](https://github.com/yanjinhuagood/WPFDevelopers/stargazers) [](https://atomgit.com/WPFDevelopersOrg/WPFDevelopers)
## Welcome to WPFDevelopers
-# __最新请使用 Nuget 预览版包__ |[下载可执行程序EXE](https://foruda.gitee.com/attach_file/1688956477367725173/net40.zip?token=71326e788298fd73e4e1dfd46558a23e&ts=1688956652&attname=net40.zip) |[项目模板下载VSIX](resources/WPFDevelopersResource/WPFDevelopers.vsix)
+# 最新请使用 NuGet 预览版包
# [最新 WPFDevelopers .Net4.5 至 Net10.0 版本如何编译 👀](https://mp.weixin.qq.com/s/M8as_AsVAFsiImDhaX7TKQ)
@@ -28,6 +88,8 @@
### [ 文档中心 → 快速开始](docs/zh/getting-started.md)
+示例导航中的蓝灰色 `DEMO` 标识表示示例专属实现或组合效果,并非 WD 内置控件,请参考示例源码。`DEMO` 与表示更新状态的 `NEW / UPDATE` 独立,同一项可以同时显示两类标识。
+
### 此项目包含了 微信公众号 《 WPF开发者》 日常开发分享,欢迎Star 。
### 运行环境 Visual Studio 2026
@@ -66,7 +128,7 @@
### 支持者
-
+
### 贡献者
@@ -514,7 +576,7 @@ xmlns:wd="https://github.com/WPFDevelopersOrg/WPFDevelopers"
----------
-### CropControl(WPF实现图片切成九宫格控件)
+### ImageCrop(WPF实现图片九宫格分块效果)
@@ -683,7 +745,7 @@ xmlns:wd="https://github.com/WPFDevelopersOrg/WPFDevelopers"
----------
-### WpfPieControl(WPF实现统计图(饼图仿LiveCharts))
+### PieSegment(WPF实现分段饼图示例)
@@ -764,4 +826,4 @@ xmlns:wd="https://github.com/WPFDevelopersOrg/WPFDevelopers"
----------
- ~~底线~~
+
diff --git a/README.md b/README.md
index d6d39299..798bd720 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,67 @@
+
+
+## About
+
+WPFDevelopers provides reusable controls, application-wide themes, and interactive samples for WPF projects. It supports target frameworks from .NET Framework 4.0 through .NET 10. See the [quick start guide](docs/en/getting-started.md) for framework and environment details.
+
+| Themes | Controls | Samples |
+| --- | --- | --- |
+| Light / Dark themes and customizable accent colors | Buttons, inputs, navigation, charts, windows, and more | Sample applications with implementation and composition examples |
+
+## Quick start
+
+Install the stable NuGet package:
+
+```powershell
+Install-Package WPFDevelopers
+```
+
+To try the latest features, install the preview package:
+
+```powershell
+Install-Package WPFDevelopers -Pre
+```
+
+Then follow the [quick start guide](docs/en/getting-started.md) to configure `App.xaml` and use the controls.
+
+## Documentation and resources
+
+- [Quick start and supported .NET versions](docs/en/getting-started.md)
+- [MapView guide](docs/en/mapview.md)
+- [Sample project source](src/WPFDevelopers.Samples.Shared/ExampleViews/)
+- [GitHub](https://github.com/WPFDevelopersOrg/WPFDevelopers) · [AtomGit](https://atomgit.com/WPFDevelopersOrg/WPFDevelopers) · [Gitee](https://gitee.com/WPFDevelopersOrg/WPFDevelopers)
+- [中文 README](README-zh.md)
+
+## Control preview
+
+
+
+The full collection of control demos and animated previews is preserved below. Items marked `DEMO` may be sample-only implementations or compositions rather than built-in WD controls; refer to the corresponding source.
+
+
+Show the full demo gallery and community information
+
[中文](https://gitee.com/WPFDevelopersOrg/WPFDevelopers/blob/master/README-zh.md)
@@ -26,6 +90,8 @@
### [Documentation Center → Quick Start](docs/en/getting-started.md)
+The sample navigation marks sample-only implementations and composed effects with a blue-gray `DEMO` badge. These are not built-in WD controls; refer to the sample source. `DEMO` is independent of `NEW` / `UPDATE`, so both badges can appear on the same item.
+
### Visual Studio 2026
System Design
@@ -65,7 +131,7 @@ If you think our open source software is helpful to you, please scan the QR code
### Backers
-
+
### Contributors
@@ -487,7 +553,7 @@ xmlns:wd="https://github.com/WPFDevelopersOrg/WPFDevelopers"
----------
-### CropControl
+### ImageCrop
@@ -663,7 +729,7 @@ xmlns:wd="https://github.com/WPFDevelopersOrg/WPFDevelopers"
----------
-### WpfPieControl
+### PieSegment
@@ -744,5 +810,4 @@ xmlns:wd="https://github.com/WPFDevelopersOrg/WPFDevelopers"
----------
- ~~end~~
-
+
diff --git a/docs/en/getting-started.md b/docs/en/getting-started.md
index 85dc650c..6a87eda4 100644
--- a/docs/en/getting-started.md
+++ b/docs/en/getting-started.md
@@ -17,8 +17,6 @@ WPFDevelopers covers the full spectrum from .NET Framework 4.0 to .NET 10:
- Visual Studio 2026
- .NET Framework 4.0 or later / .NET Core 3.0 or later
----
-
## MapView Guide
If you need to use the map control, start with:
@@ -108,6 +106,107 @@ Then use WD controls:
```
+### ColorPicker Usage
+
+`ColorPicker` remains an inline panel. Its format dropdown selects RGB, HSL, or HEX directly; set `ColorType` to choose the initial format.
+
+```xml
+
+```
+
+Set `DisplayMode="Popup"` on the same `ColorPicker` to show a clickable swatch that opens the panel. The default, `DisplayMode="Inline"`, preserves the existing inline display:
+
+```xml
+
+
+```
+
+- `SelectedColor` is a `Color` and binds two-way by default. Changes are applied immediately, without confirmation.
+- `ShowColorText` defaults to `False`. Enable it to display HEX beside the swatch: `#RRGGBB` for opaque colors, or `#AARRGGBB` otherwise.
+- `SwatchSize` is the swatch side length, defaulting to 18. Use positive values such as 24 or 32; trigger dimensions also include padding and borders.
+- `IsDropDownOpen` supports two-way binding. Click outside or press Esc to close; F4 or Alt+Down toggles the popup. Space opens it when the trigger has focus.
+- Mouse activation opens the panel on release so the popup can capture outside clicks. Outside-click dismissal remains available after changing formats.
+- `ShowColorText`, `SwatchSize`, and `IsDropDownOpen` apply to Popup mode; Inline mode cannot open a popup. Switching `DisplayMode` at runtime closes the popup and preserves the color and format.
+- `SelectedColorChanged` is a bubbling color-change event. Both modes share the color panel and theme resources. In Popup mode, `Width`, `Height`, and `Padding` configure the trigger, not the inner panel.
+
+### GridSplitter Usage
+
+`GridSplitter` is a standard WPF control and does not require the `wd:` prefix. After configuring the theme above, its default style has a transparent background and a centered three-dot grip. Hovering hides the dots and highlights the splitter with the theme color; leaving restores the grip.
+
+> The three-dot grip requires a library version containing this change. Earlier NuGet packages may not include this style.
+
+#### Vertical Splitter: Side-by-Side Panes
+
+Place the splitter in a dedicated `Auto` column and set `Width` and `ResizeDirection="Columns"`:
+
+```xml
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+```
+
+#### Horizontal Splitter: Stacked Panes
+
+Place the splitter in a dedicated `Auto` row and set `Height` and `ResizeDirection="Rows"`. The three-dot grip rotates to a horizontal arrangement:
+
+```xml
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+```
+
+Configuration notes:
+
+- Set `ResizeDirection` explicitly: `Columns` resizes adjacent columns; `Rows` resizes adjacent rows. The current grip style rotates through the `Rows` trigger, not through the effective direction inferred by `Auto`.
+- `ResizeBehavior="PreviousAndNext"` resizes the rows or columns on either side of the splitter, matching the dedicated row/column layouts above.
+- `ShowsPreview="True"` previews the resize and applies it on release; `False` resizes immediately. Preview mode requires an `AdornerLayer` in the visual tree, which standard WPF windows normally provide.
+- Set `MinWidth` / `MinHeight` on content columns/rows to prevent panes from becoming too small.
+- `Margin="2,0"` adds 2 DIPs on each side; `Margin="0,2"` adds 2 DIPs above and below. Margins on neighboring containers add to this spacing, so prefer configuring the gap on the splitter alone. The transparent background remains hit-testable for dragging.
+- `Foreground` controls the dot color; the hover background uses the theme resource `WD.PrimaryBrush`.
+
+Find the interactive demo under **Basic → GridSplitter** in the sample application. See [GridSplitterExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/Basics/GridSplitterExample.xaml) for the source.
+
### MarkdownViewer Usage
`wd:MarkdownViewer` renders Markdown content as rich text in WPF, which is ideal for README files, help documentation, changelogs, and in-app knowledge content. It supports common Markdown elements such as headings, lists, blockquotes, code blocks, tables, links, and images.
@@ -239,6 +338,35 @@ If you need to display a README, help document, release notes, or internal docum
```
+#### Back-to-top and back-to-bottom
+
+Set `ScrollViewerBehavior.IsBackToTopEnabled` and/or `ScrollViewerBehavior.IsBackToBottomEnabled` to `True` on a scrollable control. The corresponding button appears at the bottom-right while the pointer or keyboard focus is within the control, and hides when the content reaches its destination.
+
+```xml
+
+
+
+
+
+
+
+
+
+```
+
+The behavior can also be set directly on `ScrollViewer`, `WDScrollViewer`, or `TreeView`. For a `Panel`, set it on the containing `ScrollViewer` because panels do not provide scrolling themselves. It does not replace the `ItemsPanel`, so list virtualization is preserved.
+
+Open the **Attached Properties** menu in the sample application to see an interactive example.
+
### 3. Static Resource Styles
```xml
@@ -280,7 +408,9 @@ WD provides a set of theme resources you can reference in XAML:
## Complete Control Catalog
-> **Important**: Controls marked 🟡 Sample-only are defined in `WPFDevelopers.Samples.Shared/Controls/` and are **NOT** part of the NuGet package (`wd:` namespace). They are only available in the sample project. All other controls can be used directly via the `wd:` prefix after NuGet installation.
+> **Important**: Implementations marked 🟡 Sample-only live in the sample project's `Controls/` or `ExampleViews/` folders and are not shipped as built-in WD controls in the NuGet package. They may compose native WPF controls with WD styles, controls, or helpers.
+
+The sample navigation identifies these implementations and composed effects with a blue-gray `DEMO` badge. Hover for an explanation; the tooltip follows the selected language. `NEW` and `UPDATE` remain independent change-status badges and can appear alongside `DEMO`; for example, ActivityFeed can show both `DEMO` and `UPDATE`. Ordinary usage samples for built-in WD controls and helpers do not receive `DEMO`.
### Windows & Navigation
@@ -338,11 +468,11 @@ WD provides a set of theme resources you can reference in XAML:
| `wd:IPEditBox` | NuGet | [IPEditBoxExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/IPEditBoxExample.xaml) | IP address input |
| `wd:MultiSelectComboBox` | NuGet | [MultiSelectComboBoxExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/MultiSelectComboBoxExample.xaml) | Multi-select combo box |
| 🟡 MultiSelectSearchComboBox | Sample-only | [MultiSelectSearchComboBoxExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/MultiSelectSearchComboBoxExample.xaml) | Searchable multi-select combo box |
-| `wd:Password` | NuGet | [PasswordExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/Passwrod/PasswordExample.xaml) | Password show/hide toggle |
+| 🟡 Password | Sample-only | [PasswordExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/Passwrod/PasswordExample.xaml) | Composed password show/hide sample |
| `wd:VerifyCode` | NuGet | [VerifyCodeExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/VerifyCodeExample.xaml) | CAPTCHA drawing |
| 🟡 RoundPicker | Sample-only | [RoundPickerExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/RoundPickerExample.xaml) | Circular color picker |
-| `wd:RulerControl` | NuGet | [RulerControlExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/RulerControlExample.xaml) | Ruler control |
-| 🟡 Selector | Sample-only | [SelectorExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/SelectorExample.xaml) | Selector control |
+| `wd:RulerControl` | NuGet | [RulerExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/RulerExample.xaml) | Ruler control |
+| `wd:ScrollIntoView` | NuGet | [SelectorExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/SelectorExample.xaml) | List positioning helper |
| `wd:Dial` | NuGet | [DialExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/DialExample.xaml) | Dial pad |
| `wd:GestureUnlock` | NuGet | [GestureUnlockExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/GestureUnlockExample.xaml) | Gesture pattern unlock |
| `wd:SvgViewer` | NuGet | [SvgViewerExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/SvgViewerExample.xaml) | SVG viewer |
@@ -369,14 +499,14 @@ WD provides a set of theme resources you can reference in XAML:
| `wd:ChartLine` | NuGet | [ChartLineExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/ChartLineExample.xaml) | Line chart |
| `wd:ChartPie` | NuGet | [ChartPieExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/ChartPieExample.xaml) | Pie chart |
| 🟡 Dashboard | Sample-only | [DashboardExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/DashboardExample.xaml) | Dashboard gauge (tick marks follow progress) |
-| 🟡 PieControl | Sample-only | [PieControlExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/PieControlExample.xaml) | Pie chart statistics |
+| 🟡 PieSegment | Sample-only | [PieSegmentExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/PieSegmentExample.xaml) | Segmented pie chart sample (distinct from `wd:ChartPie`) |
| `wd:Gauge` | NuGet | [GaugeExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/GaugeExample.xaml) | Gauge control |
| 🟡 LineChart | Sample-only | [LineChartExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/LineChartExample.xaml) | Line chart (alternate implementation) |
| `wd:CircleProgressBar` | NuGet | [CircleProgressBarExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/CircleProgressBarExample.xaml) | Circular progress bar |
| `wd:Step` | NuGet | [StepExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/StepExample.xaml) | Step wizard |
| `wd:BreadCrumbBar` | NuGet | [BreadCrumbBarExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/BreadCrumbBarExample.xaml) | Breadcrumb navigation |
| `wd:Pagination` | NuGet | [PaginationExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/PaginationExample.xaml) | Pagination control |
-| 🟡 TimeLineControl | Sample-only | [TimeLineExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/TimeLineExample.xaml) | Timeline (Gitee-style) |
+| 🟡 ActivityFeed | Sample-only | [ActivityFeedExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/ActivityFeedExample.xaml) | Activity feed (Gitee-style) |
| `wd:Thermometer` | NuGet | [ThermometerExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/ThermometerExample.xaml) | Thermometer |
| `wd:DataGridFilter` | NuGet | [DataGridFilterExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/DataGridFilterExample.xaml) | DataGrid column filter engine |
@@ -390,14 +520,64 @@ WD provides a set of theme resources you can reference in XAML:
| `wd:CircleMenu` | NuGet | [CircleMenuExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/CircleMenuExample.xaml) | Circular menu |
| `wd:SixGridView` | NuGet | [SixGirdViewExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/SixGirdViewExample.xaml) | Six-column grid layout |
| `wd:WaterfallPanel` | NuGet | [WaterfallPanelExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/WaterfallPanelExample.xaml) | Waterfall / masonry panel |
+| `wd:WaterfallItemsControl` | NuGet | [WaterfallPanelExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/WaterfallPanelExample.xaml) | Masonry items control with a scrolling template |
| `wd:VirtualizingWrapPanel` | NuGet | [VirtualizingWrapPanelExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/VirtualizingWrapPanelExample.xaml) | Virtualizing WrapPanel |
| 🟡 TransformLayout | Sample-only | [TransformLayoutExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/TransformLayoutExample.xaml) | Draggable, resizable, rotatable control |
| `wd:DrapView` | NuGet | [DrapViewExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/DrapView/DrapViewExample.xaml) | Drag-and-drop view |
| `wd:Spacing` (attached) | NuGet | [SpacingExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/SpacingExample.xaml) | Panel child spacing |
| `wd:PanningItems` | NuGet | [PanningItemsExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/PanningItemsExample.xaml) | Panning control (touch swipe) |
-| 🟡 ScrollViewerAnimation | Sample-only | [ScrollViewerAnimationExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/ScrollViewerAnimationExample.xaml) | Animated scrollbar |
+| `wd:WDScrollViewer` / `wd:ScrollViewerBehavior` | NuGet | [ScrollViewerAnimationExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/ScrollViewerAnimationExample.xaml) | Animated scrolling and back-to-top helper |
| `wd:IconicThumbnail` | NuGet | [IconicThumbnailExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/IconicThumbnailExample.xaml) | Iconic thumbnail |
+#### WaterfallPanel: responsive columns and virtualization
+
+Scrolling reuses cached item positions and uses per-column binary searches to select nearby items.
+Positions are rebuilt when width, data, or measured realized-item heights change.
+`WDScrollViewer` retains smooth scrolling: consecutive wheel input accumulates its target,
+while direction changes restart from the current offset. Animations last 250ms without a fixed
+40 FPS cap. Actual smoothness depends on item templates and hardware.
+These changes use APIs available in .NET Framework 4.0. Windows 7 requires a compatible
+.NET Framework build; this does not imply Windows 7 support for modern .NET targets.
+
+For data binding, use `WaterfallItemsControl` without an outer `ScrollViewer`:
+
+```xml
+
+
+
+
+
+
+
+```
+
+It inherits `ItemsSource`, `ItemTemplate`, and `ItemTemplateSelector`, enables recycling by default,
+and exposes `Columns`, `MinColumnWidth`, `Spacing`, and `EstimatedItemHeight`.
+Use `ScrollViewer.VerticalScrollBarVisibility` to control the scrollbar.
+A finite host height is still required for virtualization. Use `WaterfallPanel` for direct XAML
+children or custom hosts.
+
+`Columns` defaults to 3. `MinColumnWidth` defaults to 0 (fixed columns).
+A positive `MinColumnWidth` selects `max(1, floor((availableWidth + Spacing) / (MinColumnWidth + Spacing)))`
+columns. A narrow container still has one column, which may be narrower than the minimum.
+`ActualColumns` reports the selected count. With infinite available width, `Columns` is used,
+and the widest natural item width (at least `MinColumnWidth`) determines the column width.
+
+The same panel supports direct XAML children and `ItemsControl.ItemsSource`.
+For UI virtualization, give the host a finite viewport and use an `ItemsControl` template containing
+`ScrollViewer CanContentScroll="True"` with an `ItemsPresenter` as its content.
+Set `VirtualizingStackPanel.IsVirtualizing="True"` and `VirtualizingStackPanel.VirtualizationMode="Recycling"`
+on the `ItemsControl`, and use `WaterfallPanel` as its `ItemsPanel`.
+Do not wrap this host in a vertical `StackPanel` or an outer scroller providing infinite height.
+Without a finite scrolling viewport the panel generates all containers; setting `IsVirtualizing="False"`
+also generates all containers.
+
+Unmeasured items use `EstimatedItemHeight` (default 200). Actual measurements update positions and
+the scroll extent, so distant jumps and asynchronously loaded images may cause layout shifts.
+Reserve a suitable initial height for asynchronous content.
+This is UI, not data, virtualization: metadata storage is O(item count), and layout calculation is
+O(item count × columns). The example includes XAML, MVVM, and a 5000-card virtualization tab.
+
### Animation & Effects
| Control | Source | Example File | Description |
@@ -407,7 +587,7 @@ WD provides a set of theme resources you can reference in XAML:
| `wd:EdgeLight` | NuGet | [EdgeLightExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/EdgeLightExample.xaml) | Edge marquee light |
| 🟡 RainbowButtons | Sample-only | [RainbowButtonsExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/RainbowButtonsExample.xaml) | Rainbow buttons |
| `wd:Shake` | NuGet | [ShakeExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/ShakeExample.xaml) | Window shake |
-| 🟡 BubblleControl | Sample-only | [BubblleControlExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/BubblleControlExample.xaml) | Bubble animation |
+| 🟡 BubbleSelection | Sample-only | [BubbleSelectionExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/BubbleSelectionExample.xaml) | Bubble selection sample |
| `wd:StarrySky` | NuGet | [StarrySkyExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/StarrySkyExample.xaml) | Starry sky animation |
| 🟡 SnowCanvas | Sample-only | [SnowCanvasExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/SnowCanvasExample.xaml) | Christmas tree & snow canvas |
| 🟡 SpeedRockets | Sample-only | [SpeedRocketsExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/SpeedRockets/SpeedRocketsExample.xaml) | Speed rocket animation |
@@ -435,7 +615,7 @@ WD provides a set of theme resources you can reference in XAML:
| `wd:ScreenCut` | NuGet | [ScreenCutExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/ScreenCutExample.xaml) | Screen capture (pen / arrow annotation) |
| `wd:CropImage` | NuGet | [CropImageExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/CropImageExample.xaml) | Image cropping |
| `wd:CropAvatar` | NuGet | [CropAvatarExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/CropAvatar/CropAvatarExample.xaml) | Avatar cropping selector |
-| 🟡 CropControl | Sample-only | [CropControlExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/CropControlExample.xaml) | Image nine-grid cutter |
+| 🟡 ImageCrop | Sample-only | [ImageCropExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/ImageCropExample.xaml) | Image nine-grid tiling effect sample |
| 🟡 CutImage | Sample-only | [CutImageExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/CutImageExample.xaml) | User avatar cropping solution |
| `wd:Magnifier` | NuGet | [MagnifierExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/MagnifierExample.xaml) | Magnifier |
@@ -455,7 +635,7 @@ WD provides a set of theme resources you can reference in XAML:
| Control | Source | Example File | Description |
|---------|--------|-------------|-------------|
| 🟡 ZooSemy | Sample-only | [ZooSemyExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/ZooSemy/ZooSemyExample.xaml) | Skeuomorphic rotary knob (volume) |
-| 🟡 OtherControl | Sample-only | [OtherControlExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/OtherControlExample.xaml) | Torch & other fun controls |
+| 🟡 Flame | Sample-only | [FlameExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/FlameExample.xaml) | Flame animation |
| 🟡 Desktop | Sample-only | [DesktopBackground.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/Desktop/DesktopBackground.xaml) | Dynamic desktop wallpaper |
| 🟡 AMap | Sample-only | [BingAMapExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/Map/BingAMapExample.xaml) | Map integration (Bing / AutoNavi) |
| 🟡 LoginWindow | Sample-only | [LoginExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/LoginWindow/LoginExample.xaml) | Login window template |
diff --git a/docs/zh/getting-started.md b/docs/zh/getting-started.md
index 69d4ef40..307a14b8 100644
--- a/docs/zh/getting-started.md
+++ b/docs/zh/getting-started.md
@@ -17,8 +17,6 @@ WPFDevelopers 覆盖从 .NET Framework 4.0 到 .NET 10 的完整版本线:
- Visual Studio 2026
- .NET Framework 4.0 或更高 / .NET Core 3.0 或更高
----
-
## MapView 专题文档
如果你要使用地图控件,建议直接阅读:
@@ -108,6 +106,107 @@ xmlns:wd="https://github.com/WPFDevelopersOrg/WPFDevelopers"
```
+### ColorPicker 使用方式
+
+`ColorPicker` 保留内嵌面板用法,底部下拉框可直接选择 RGB、HSL 或 HEX,支持通过 `ColorType` 设置初始格式。
+
+```xml
+
+```
+
+同一个 `ColorPicker` 设置 `DisplayMode="Popup"` 后,提供点击色块打开面板的用法;默认 `DisplayMode="Inline"` 保留现有内嵌展示:
+
+```xml
+
+
+```
+
+- `SelectedColor` 为 `Color`,默认双向绑定,修改颜色时立即同步,无需确认。
+- `ShowColorText` 默认为 `False`;启用后在色块右侧显示 HEX,不透明颜色为 `#RRGGBB`,带透明度颜色为 `#AARRGGBB`。
+- `SwatchSize` 为色块边长,默认为 18,可设置为 24、32 等正数;触发器总尺寸还包含 `Padding` 和边框。
+- `IsDropDownOpen` 支持双向绑定;点击外部或按 Esc 关闭,F4 或 Alt+下箭头切换打开状态,也可通过聚焦触发器后按空格打开。
+- 鼠标点击触发器时,在松开后展开面板,以保证外部点击关闭所需的鼠标捕获;切换格式后仍可点击外部关闭。
+- `ShowColorText`、`SwatchSize` 和 `IsDropDownOpen` 用于 Popup 模式,Inline 模式不会打开弹窗。运行时切换 `DisplayMode` 会关闭弹窗并保留颜色和格式。
+- `SelectedColorChanged` 为颜色改变时触发的冒泡事件。两种模式共用取色逻辑及主题资源,控件的 `Width`、`Height` 和 `Padding` 在 Popup 模式下设置触发器尺寸,不影响内部面板。
+
+### GridSplitter 使用方式
+
+`GridSplitter` 是标准 WPF 控件,不需要 `wd:` 前缀。完成上述主题配置后即可使用默认样式:背景透明、居中显示三个圆点,鼠标进入时隐藏圆点并显示主题色分隔条,移出后恢复。
+
+> 三点手柄样式需要使用包含此改动的控件库版本;较早的 NuGet 包可能尚未包含该样式。
+
+#### 垂直分隔条:左右分栏
+
+使用独立的 `Auto` 列放置分隔条,设置 `Width` 和 `ResizeDirection="Columns"`:
+
+```xml
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+```
+
+#### 水平分隔条:上下分栏
+
+使用独立的 `Auto` 行放置分隔条,设置 `Height` 和 `ResizeDirection="Rows"`;此时三个圆点会旋转为水平排列:
+
+```xml
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+```
+
+配置要点:
+
+- 显式设置 `ResizeDirection`:`Columns` 调整左右列宽,`Rows` 调整上下行高。当前手柄样式通过 `Rows` 触发器旋转三点,不会根据 `Auto` 的实际拖动方向自动旋转。
+- `ResizeBehavior="PreviousAndNext"` 调整分隔条两侧的行或列,适合上述独立行/列布局。
+- `ShowsPreview="True"` 拖动时显示预览,松开后应用尺寸;`False` 则实时调整。预览模式需要所在的可视树中存在 `AdornerLayer`,标准 WPF 窗口通常已提供。
+- 为内容行/列设置 `MinWidth` / `MinHeight`,避免拖动后内容区过小。
+- `Margin="2,0"` 表示左右各留 2 DIP;`Margin="0,2"` 表示上下各留 2 DIP。相邻容器的外边距会叠加,建议统一在分隔条上配置间距。透明背景仍保留拖动命中区域。
+- `Foreground` 控制圆点颜色;悬停背景使用主题资源 `WD.PrimaryBrush`。
+
+交互示例位于示例程序的 **基础控件 → GridSplitter(网格分隔条)**,源码参见 [GridSplitterExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/Basics/GridSplitterExample.xaml)。
+
### MarkdownViewer 使用方式
`wd:MarkdownViewer` 用于将 Markdown 文本渲染为 WPF 中的富文本展示,适合展示说明文档、README、日志、知识库内容等。它支持标题、列表、引用、代码块、表格、链接、图片等常见 Markdown 语法。
@@ -243,6 +342,35 @@ public string MarkdownText { get; } = "# WPFDevelopers\n\n- 支持标题\n- 支
```
+#### 回到顶部和回到底部
+
+在可滚动控件上将 `ScrollViewerBehavior.IsBackToTopEnabled` 和/或 `ScrollViewerBehavior.IsBackToBottomEnabled` 设置为 `True`。当光标或键盘焦点进入控件时,对应按钮会显示在控件右下角;到达目标位置后自动隐藏。
+
+```xml
+
+
+
+
+
+
+
+
+
+```
+
+该附加属性也可直接用于 `ScrollViewer`、`WDScrollViewer` 和 `TreeView`。`Panel` 本身不提供滚动能力,应将属性设置在包裹它的 `ScrollViewer` 上。该行为不会修改 `ItemsPanel`,因此不会影响列表虚拟化。
+
+示例程序中可打开 **附加属性** 菜单查看交互示例。
+
### 3. 静态资源样式
```xml
@@ -284,7 +412,9 @@ WD 提供了一套主题资源,可在 XAML 中引用:
## 控件全览
-> **重要说明**:以下列表中带有 🟡 示例专属 标记的控件定义在 `WPFDevelopers.Samples.Shared/Controls/` 目录中,**不**属于 NuGet 包(`wd:` 命名空间),仅在示例项目中可用。其余控件均可通过 NuGet 安装后以 `wd:` 前缀直接使用。
+> **重要说明**:以下列表中带有 🟡 示例专属 标记的实现位于示例项目的 `Controls/` 或 `ExampleViews/` 中,不作为 WD 内置控件随 NuGet 包提供。示例可能组合使用 WPF 原生控件及 WD 样式、控件或辅助功能。
+
+示例导航使用蓝灰色 `DEMO` 标识这些示例专属实现或组合效果。悬停可查看说明,中英文切换时提示同步更新。`NEW`(新增)和 `UPDATE`(更新)仍只表示更新状态,与 `DEMO` 独立,可同时显示;例如“活动记录”可以同时显示 `DEMO` 和 `UPDATE`。WD 内置控件及辅助功能的常规用法示例不加 `DEMO`。
### 窗口与导航
@@ -342,11 +472,11 @@ WD 提供了一套主题资源,可在 XAML 中引用:
| `wd:IPEditBox` | NuGet | [IPEditBoxExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/IPEditBoxExample.xaml) | IP 地址输入框 |
| `wd:MultiSelectComboBox` | NuGet | [MultiSelectComboBoxExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/MultiSelectComboBoxExample.xaml) | 下拉多选框 |
| 🟡 MultiSelectSearchComboBox | 示例专属 | [MultiSelectSearchComboBoxExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/MultiSelectSearchComboBoxExample.xaml) | 下拉搜索多选框 |
-| `wd:Password` | NuGet | [PasswordExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/Passwrod/PasswordExample.xaml) | 密码显示/隐藏切换 |
+| 🟡 Password | 示例专属 | [PasswordExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/Passwrod/PasswordExample.xaml) | 密码显示/隐藏组合示例 |
| `wd:VerifyCode` | NuGet | [VerifyCodeExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/VerifyCodeExample.xaml) | 验证码绘制 |
| 🟡 RoundPicker | 示例专属 | [RoundPickerExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/RoundPickerExample.xaml) | 圆形颜色选择器 |
-| `wd:RulerControl` | NuGet | [RulerControlExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/RulerControlExample.xaml) | 刻度尺控件 |
-| 🟡 Selector | 示例专属 | [SelectorExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/SelectorExample.xaml) | 选择器控件 |
+| `wd:RulerControl` | NuGet | [RulerExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/RulerExample.xaml) | 刻度尺控件 |
+| `wd:ScrollIntoView` | NuGet | [SelectorExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/SelectorExample.xaml) | 列表定位辅助功能 |
| `wd:Dial` | NuGet | [DialExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/DialExample.xaml) | 拨号盘控件 |
| `wd:GestureUnlock` | NuGet | [GestureUnlockExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/GestureUnlockExample.xaml) | 手势解锁 |
| `wd:SvgViewer` | NuGet | [SvgViewerExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/SvgViewerExample.xaml) | SVG 查看器 |
@@ -373,14 +503,14 @@ WD 提供了一套主题资源,可在 XAML 中引用:
| `wd:ChartLine` | NuGet | [ChartLineExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/ChartLineExample.xaml) | 折线图 |
| `wd:ChartPie` | NuGet | [ChartPieExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/ChartPieExample.xaml) | 饼图 |
| 🟡 Dashboard | 示例专属 | [DashboardExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/DashboardExample.xaml) | 仪表盘(刻度跟随进度) |
-| 🟡 PieControl | 示例专属 | [PieControlExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/PieControlExample.xaml) | 统计饼图 |
+| 🟡 PieSegment | 示例专属 | [PieSegmentExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/PieSegmentExample.xaml) | 分段饼图示例(区别于 `wd:ChartPie`) |
| `wd:Gauge` | NuGet | [GaugeExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/GaugeExample.xaml) | 仪表盘 |
| 🟡 LineChart | 示例专属 | [LineChartExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/LineChartExample.xaml) | 折线图(另一实现) |
| `wd:CircleProgressBar` | NuGet | [CircleProgressBarExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/CircleProgressBarExample.xaml) | 环形进度条 |
| `wd:Step` | NuGet | [StepExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/StepExample.xaml) | 步骤条向导 |
| `wd:BreadCrumbBar` | NuGet | [BreadCrumbBarExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/BreadCrumbBarExample.xaml) | 面包屑导航栏 |
| `wd:Pagination` | NuGet | [PaginationExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/PaginationExample.xaml) | 分页控件 |
-| 🟡 TimeLineControl | 示例专属 | [TimeLineExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/TimeLineExample.xaml) | 时间轴(仿 Gitee) |
+| 🟡 ActivityFeed | 示例专属 | [ActivityFeedExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/ActivityFeedExample.xaml) | 活动记录(仿 Gitee) |
| `wd:Thermometer` | NuGet | [ThermometerExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/ThermometerExample.xaml) | 温度计 |
| `wd:DataGridFilter` | NuGet | [DataGridFilterExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/DataGridFilterExample.xaml) | DataGrid 列过滤引擎 |
@@ -394,14 +524,80 @@ WD 提供了一套主题资源,可在 XAML 中引用:
| `wd:CircleMenu` | NuGet | [CircleMenuExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/CircleMenuExample.xaml) | 圆形菜单 |
| `wd:SixGridView` | NuGet | [SixGirdViewExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/SixGirdViewExample.xaml) | 六宫格布局 |
| `wd:WaterfallPanel` | NuGet | [WaterfallPanelExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/WaterfallPanelExample.xaml) | 瀑布流面板 |
+| `wd:WaterfallItemsControl` | NuGet | [WaterfallPanelExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/WaterfallPanelExample.xaml) | 内置滚动模板的瀑布流集合控件 |
| `wd:VirtualizingWrapPanel` | NuGet | [VirtualizingWrapPanelExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/VirtualizingWrapPanelExample.xaml) | 虚拟化 WrapPanel |
| 🟡 TransformLayout | 示例专属 | [TransformLayoutExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/TransformLayoutExample.xaml) | 可拖拽旋转缩放控件 |
| `wd:DrapView` | NuGet | [DrapViewExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/DrapView/DrapViewExample.xaml) | 拖拽视图控件 |
| `wd:Spacing`(附加属性) | NuGet | [SpacingExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/SpacingExample.xaml) | 面板子元素间距 |
| `wd:PanningItems` | NuGet | [PanningItemsExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/PanningItemsExample.xaml) | 平移控件 |
-| 🟡 ScrollViewerAnimation | 示例专属 | [ScrollViewerAnimationExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/ScrollViewerAnimationExample.xaml) | 带动画的滚动条 |
+| `wd:WDScrollViewer` / `wd:ScrollViewerBehavior` | NuGet | [ScrollViewerAnimationExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/ScrollViewerAnimationExample.xaml) | 动画滚动视图与回到顶部辅助功能 |
| `wd:IconicThumbnail` | NuGet | [IconicThumbnailExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/IconicThumbnailExample.xaml) | 图标缩略图 |
+#### WaterfallPanel:响应式列数与虚拟化
+
+瀑布流滚动复用项目位置缓存,并通过列内二分查找选择视口附近的项目;
+宽度、数据或已实现项目的测量高度变化时才重建位置。
+`WDScrollViewer` 保留平滑滚动,连续同向滚轮输入累计目标位置,反向输入从当前位置开始,
+动画时长为 250ms,不再固定限制为 40 FPS。实际流畅度取决于项目模板和设备性能。
+这些优化只使用 .NET Framework 4.0 已有 API;Win7 应选择兼容的 .NET Framework 构建,
+不能因此认为现代 .NET 目标也支持 Win7。
+
+数据绑定场景推荐使用 `WaterfallItemsControl`,不需要再套外层 `ScrollViewer`:
+
+```xml
+
+
+
+
+
+
+
+```
+
+它继承 `ItemsControl` 的 `ItemsSource`、`ItemTemplate`、`ItemTemplateSelector`,
+默认启用容器回收,并提供 `Columns`、`MinColumnWidth`、`Spacing`、`EstimatedItemHeight`。
+通过 `ScrollViewer.VerticalScrollBarVisibility` 控制滚动条,仍需由父布局提供有限高度才能虚拟化。
+直接 XAML 子项或自行配置宿主时继续使用 `WaterfallPanel`。
+
+`Columns` 默认为 3;`MinColumnWidth` 默认为 0,保留固定列数。
+设置 `MinColumnWidth="200"` 后,列数按 `floor((可用宽度 + Spacing) / (MinColumnWidth + Spacing))`
+计算,最少一列。容器不足最小列宽时,单列会缩小到容器宽度;`ActualColumns` 可读取当前列数。
+无限宽度下使用 `Columns`,按子项最大自然宽度(且不小于 `MinColumnWidth`)计算列宽。
+
+同一个 `WaterfallPanel` 支持直接 XAML 子元素和 `ItemsControl.ItemsSource`。
+真正的 UI 虚拟化需要有限视口,并由 `ScrollViewer` 通过 `CanContentScroll="True"`
+将滚动交给面板。例如:
+
+```xml
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+```
+
+不要将该虚拟化宿主放入垂直 `StackPanel` 或另一个提供无限高度的外层滚动容器;
+缺少有限视口或滚动协作时会退回全部容器布局。`IsVirtualizing="False"` 也会生成全部容器。
+未测量项使用 `EstimatedItemHeight`(默认 200),测得真实高度后会修正布局与滚动范围,
+因此远距离跳转、图片异步加载时位置可能变化。异步内容应预留合理高度。
+这是容器虚拟化,不是数据虚拟化:布局元数据仍随项目数增长,布局计算为 O(项目数 × 列数)。
+示例包含 XAML、MVVM 和 5000 个不同高度卡片的虚拟化演示。
+
### 动画与特效
| 控件名 | 来源 | 示例文件 | 说明 |
@@ -411,7 +607,7 @@ WD 提供了一套主题资源,可在 XAML 中引用:
| `wd:EdgeLight` | NuGet | [EdgeLightExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/EdgeLightExample.xaml) | 边框跑马灯 |
| 🟡 RainbowButtons | 示例专属 | [RainbowButtonsExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/RainbowButtonsExample.xaml) | 彩虹按钮 |
| `wd:Shake` | NuGet | [ShakeExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/ShakeExample.xaml) | 窗体抖动 |
-| 🟡 BubblleControl | 示例专属 | [BubblleControlExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/BubblleControlExample.xaml) | 泡泡动画控件 |
+| 🟡 BubbleSelection | 示例专属 | [BubbleSelectionExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/BubbleSelectionExample.xaml) | 气泡选择示例 |
| `wd:StarrySky` | NuGet | [StarrySkyExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/StarrySkyExample.xaml) | 星空动画 |
| 🟡 SnowCanvas | 示例专属 | [SnowCanvasExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/SnowCanvasExample.xaml) | 圣诞树雪花 Canvas |
| 🟡 SpeedRockets | 示例专属 | [SpeedRocketsExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/SpeedRockets/SpeedRocketsExample.xaml) | 加速火箭动画 |
@@ -439,7 +635,7 @@ WD 提供了一套主题资源,可在 XAML 中引用:
| `wd:ScreenCut` | NuGet | [ScreenCutExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/ScreenCutExample.xaml) | 截屏工具(画笔/箭头标注) |
| `wd:CropImage` | NuGet | [CropImageExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/CropImageExample.xaml) | 图片裁剪 |
| `wd:CropAvatar` | NuGet | [CropAvatarExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/CropAvatar/CropAvatarExample.xaml) | 头像裁剪选择器 |
-| 🟡 CropControl | 示例专属 | [CropControlExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/CropControlExample.xaml) | 图片切九宫格控件 |
+| 🟡 ImageCrop | 示例专属 | [ImageCropExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/ImageCropExample.xaml) | 图片九宫格分块效果示例 |
| 🟡 CutImage | 示例专属 | [CutImageExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/CutImageExample.xaml) | 用户头像裁剪方案 |
| `wd:Magnifier` | NuGet | [MagnifierExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/MagnifierExample.xaml) | 放大镜 |
@@ -459,7 +655,7 @@ WD 提供了一套主题资源,可在 XAML 中引用:
| 控件名 | 来源 | 示例文件 | 说明 |
|--------|------|----------|------|
| 🟡 ZooSemy | 示例专属 | [ZooSemyExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/ZooSemy/ZooSemyExample.xaml) | 拟物旋转按钮(音量旋钮) |
-| 🟡 OtherControl | 示例专属 | [OtherControlExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/OtherControlExample.xaml) | 火炬等趣味控件 |
+| 🟡 Flame | 示例专属 | [FlameExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/FlameExample.xaml) | 火苗动画 |
| 🟡 Desktop | 示例专属 | [DesktopBackground.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/Desktop/DesktopBackground.xaml) | 动态桌面壁纸(视频播放) |
| 🟡 AMap | 示例专属 | [BingAMapExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/Map/BingAMapExample.xaml) | 地图集成(Bing/高德) |
| 🟡 LoginWindow | 示例专属 | [LoginExample.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/LoginWindow/LoginExample.xaml) | 登录窗口模板 |
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/Package.props b/src/Package.props
index 54a1ca80..615f3c1a 100644
--- a/src/Package.props
+++ b/src/Package.props
@@ -7,9 +7,9 @@
true
snupkg
Copyright © WPFDevelopersOrg 2026
- 0.3.0.0
- 0.3.0.0
- 0.3.0.0
+ 0.4.0.0
+ 0.4.0.0
+ 0.4.0.0
https://github.com/WPFDevelopersOrg/WPFDevelopers
Debug;Release;Debug-.NET40;Release-.NET40
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
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 @@
-
+
@@ -2344,6 +2385,15 @@
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
@@ -6567,6 +6832,57 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -7405,6 +7804,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1204,8 +1225,18 @@
-
+
+
+
+
+
+
+
+
+
+
+
@@ -1217,8 +1248,18 @@
-
+
+
+
+
+
+
+
+
+
+
+
@@ -1742,7 +1783,7 @@
-
+
@@ -2346,6 +2387,15 @@
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
@@ -6599,6 +6864,57 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -7437,6 +7836,30 @@
+
+
-
-
+
+
\ No newline at end of file
diff --git a/src/WPFDevelopers.Samples.Shared/Controls/TimeLine/TimeLineItem.cs b/src/WPFDevelopers.Samples.Shared/Controls/ActivityFeed/ActivityFeedItem.cs
similarity index 83%
rename from src/WPFDevelopers.Samples.Shared/Controls/TimeLine/TimeLineItem.cs
rename to src/WPFDevelopers.Samples.Shared/Controls/ActivityFeed/ActivityFeedItem.cs
index c34a0fd3..b33c9b90 100644
--- a/src/WPFDevelopers.Samples.Shared/Controls/TimeLine/TimeLineItem.cs
+++ b/src/WPFDevelopers.Samples.Shared/Controls/ActivityFeed/ActivityFeedItem.cs
@@ -4,36 +4,36 @@
namespace WPFDevelopers.Samples.Controls
{
- public class TimeLineItem : Control
+ public class ActivityFeedItem : Control
{
public static readonly DependencyProperty IsBottomProperty =
- DependencyProperty.Register("IsBottom", typeof(bool), typeof(TimeLineItem), new PropertyMetadata(false));
+ DependencyProperty.Register("IsBottom", typeof(bool), typeof(ActivityFeedItem), new PropertyMetadata(false));
public static readonly DependencyProperty ItemTypeProperty =
- DependencyProperty.Register("ItemType", typeof(ItemTypeEnum), typeof(TimeLineItem));
+ DependencyProperty.Register("ItemType", typeof(ItemTypeEnum), typeof(ActivityFeedItem));
public static readonly DependencyProperty TextProperty =
- DependencyProperty.Register("Text", typeof(string), typeof(TimeLineItem),
+ DependencyProperty.Register("Text", typeof(string), typeof(ActivityFeedItem),
new PropertyMetadata(string.Empty));
public static readonly DependencyProperty HeadProperty =
- DependencyProperty.Register("Head", typeof(string), typeof(TimeLineItem),
+ DependencyProperty.Register("Head", typeof(string), typeof(ActivityFeedItem),
new PropertyMetadata(string.Empty));
public static readonly DependencyProperty CommonTemplateProperty =
- DependencyProperty.Register("CommonTemplate", typeof(DataTemplate), typeof(TimeLineItem));
+ DependencyProperty.Register("CommonTemplate", typeof(DataTemplate), typeof(ActivityFeedItem));
public static readonly DependencyProperty TextTemplateProperty =
- DependencyProperty.Register("TextTemplate", typeof(DataTemplate), typeof(TimeLineItem));
+ DependencyProperty.Register("TextTemplate", typeof(DataTemplate), typeof(ActivityFeedItem));
public static readonly DependencyProperty BackgroundColorProperty =
- DependencyProperty.Register("BackgroundColor", typeof(Brush), typeof(TimeLineItem),
+ DependencyProperty.Register("BackgroundColor", typeof(Brush), typeof(ActivityFeedItem),
new PropertyMetadata(null));
- static TimeLineItem()
+ static ActivityFeedItem()
{
- DefaultStyleKeyProperty.OverrideMetadata(typeof(TimeLineItem),
- new FrameworkPropertyMetadata(typeof(TimeLineItem)));
+ DefaultStyleKeyProperty.OverrideMetadata(typeof(ActivityFeedItem),
+ new FrameworkPropertyMetadata(typeof(ActivityFeedItem)));
}
public bool IsBottom
diff --git a/src/WPFDevelopers.Samples.Shared/Controls/BubblleControl/BubblleCanvas.cs b/src/WPFDevelopers.Samples.Shared/Controls/BubbleSelection/BubbleCanvas.cs
similarity index 98%
rename from src/WPFDevelopers.Samples.Shared/Controls/BubblleControl/BubblleCanvas.cs
rename to src/WPFDevelopers.Samples.Shared/Controls/BubbleSelection/BubbleCanvas.cs
index 471f5694..b6ed6a11 100644
--- a/src/WPFDevelopers.Samples.Shared/Controls/BubblleControl/BubblleCanvas.cs
+++ b/src/WPFDevelopers.Samples.Shared/Controls/BubbleSelection/BubbleCanvas.cs
@@ -4,7 +4,7 @@
namespace WPFDevelopers.Samples.Controls
{
- public class BubblleCanvas : Canvas
+ public class BubbleCanvas : Canvas
{
private double _bubbleItemX;
private double _bubbleItemY;
diff --git a/src/WPFDevelopers.Samples.Shared/Controls/BubblleControl/BubblleControl.cs b/src/WPFDevelopers.Samples.Shared/Controls/BubbleSelection/BubbleSelection.cs
similarity index 89%
rename from src/WPFDevelopers.Samples.Shared/Controls/BubblleControl/BubblleControl.cs
rename to src/WPFDevelopers.Samples.Shared/Controls/BubbleSelection/BubbleSelection.cs
index 5096083b..5eaeb1f6 100644
--- a/src/WPFDevelopers.Samples.Shared/Controls/BubblleControl/BubblleControl.cs
+++ b/src/WPFDevelopers.Samples.Shared/Controls/BubbleSelection/BubbleSelection.cs
@@ -12,16 +12,16 @@ namespace WPFDevelopers.Samples.Controls
[TemplatePart(Name = BorderTemplateName, Type = typeof(Border))]
[TemplatePart(Name = EllipseTemplateName, Type = typeof(Ellipse))]
[TemplatePart(Name = RotateTransformTemplateName, Type = typeof(RotateTransform))]
- public class BubblleControl : Control
+ public class BubbleSelection : Control
{
private const string BorderTemplateName = "PART_Border";
private const string EllipseTemplateName = "PART_Ellipse";
private const string RotateTransformTemplateName = "PART_EllipseRotateTransform";
private const string ListBoxTemplateName = "PART_ListBox";
- private static readonly Type _typeofSelf = typeof(BubblleControl);
+ private static readonly Type _typeofSelf = typeof(BubbleSelection);
- private ObservableCollection _items = new ObservableCollection();
+ private ObservableCollection _items = new ObservableCollection();
private Border _border;
@@ -31,13 +31,13 @@ public class BubblleControl : Control
private ItemsControl _listBox;
private static RoutedCommand _clieckCommand;
- class BubblleItem
+ class BubbleItem
{
public string Text { get; set; }
public Brush Bg { get; set; }
}
- static BubblleControl()
+ static BubbleSelection()
{
InitializeCommands();
DefaultStyleKeyProperty.OverrideMetadata(_typeofSelf, new FrameworkPropertyMetadata(_typeofSelf));
@@ -72,7 +72,7 @@ public static RoutedCommand ClickCommand
private static void OnClickCommand(object sender, ExecutedRoutedEventArgs e)
{
- var ctrl = sender as BubblleControl;
+ var ctrl = sender as BubbleSelection;
ctrl.SetValue(SelectedTextPropertyKey, e.Parameter?.ToString());
ctrl.RaiseEvent(new RoutedEventArgs(ClickEvent));
@@ -95,11 +95,11 @@ public string SelectedText
get { return (string)GetValue(SelectedTextProperty); }
}
public static readonly DependencyProperty BorderBackgroundProperty =
- DependencyProperty.Register("BorderBackground", typeof(Brush), typeof(BubblleControl),
+ DependencyProperty.Register("BorderBackground", typeof(Brush), typeof(BubbleSelection),
new PropertyMetadata(null));
public static readonly DependencyProperty EarthBackgroundProperty =
- DependencyProperty.Register("EarthBackground", typeof(Brush), typeof(BubblleControl),
+ DependencyProperty.Register("EarthBackground", typeof(Brush), typeof(BubbleSelection),
new PropertyMetadata(Brushes.DarkOrchid));
public Brush BorderBackground
{
@@ -116,7 +116,7 @@ public Brush EarthBackground
#region Property
public static readonly DependencyProperty ItemsSourceProperty =
- DependencyProperty.Register("ItemsSource", typeof(IEnumerable), typeof(BubblleControl), new PropertyMetadata(null, OnItemsSourcePropertyChanged));
+ DependencyProperty.Register("ItemsSource", typeof(IEnumerable), typeof(BubbleSelection), new PropertyMetadata(null, OnItemsSourcePropertyChanged));
public IEnumerable ItemsSource
{
get { return (IEnumerable)GetValue(ItemsSourceProperty); }
@@ -125,7 +125,7 @@ public IEnumerable ItemsSource
private static void OnItemsSourcePropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
- var ctrl = obj as BubblleControl;
+ var ctrl = obj as BubbleSelection;
var newValue = e.NewValue as IEnumerable;
if (newValue == null)
@@ -136,7 +136,7 @@ private static void OnItemsSourcePropertyChanged(DependencyObject obj, Dependenc
foreach (var item in newValue)
{
- ctrl._items.Add(new BubblleItem { Text = item, Bg = Helper.RandomBrush() });
+ ctrl._items.Add(new BubbleItem { Text = item, Bg = Helper.RandomBrush() });
}
}
diff --git a/src/WPFDevelopers.Samples.Shared/Controls/BubblleControl/BubblleControl.xaml b/src/WPFDevelopers.Samples.Shared/Controls/BubbleSelection/BubbleSelection.xaml
similarity index 93%
rename from src/WPFDevelopers.Samples.Shared/Controls/BubblleControl/BubblleControl.xaml
rename to src/WPFDevelopers.Samples.Shared/Controls/BubbleSelection/BubbleSelection.xaml
index 49c6c1e5..376d7c35 100644
--- a/src/WPFDevelopers.Samples.Shared/Controls/BubblleControl/BubblleControl.xaml
+++ b/src/WPFDevelopers.Samples.Shared/Controls/BubbleSelection/BubbleSelection.xaml
@@ -5,9 +5,9 @@
xmlns:wd="https://github.com/WPFDevelopersOrg/WPFDevelopers">
-
+
\ No newline at end of file
diff --git a/src/WPFDevelopers.Samples.Shared/Controls/CropControl/CropControl.cs b/src/WPFDevelopers.Samples.Shared/Controls/ImageCrop/ImageCrop.cs
similarity index 93%
rename from src/WPFDevelopers.Samples.Shared/Controls/CropControl/CropControl.cs
rename to src/WPFDevelopers.Samples.Shared/Controls/ImageCrop/ImageCrop.cs
index b3659df0..411be29b 100644
--- a/src/WPFDevelopers.Samples.Shared/Controls/CropControl/CropControl.cs
+++ b/src/WPFDevelopers.Samples.Shared/Controls/ImageCrop/ImageCrop.cs
@@ -11,23 +11,23 @@
namespace WPFDevelopers.Samples.Controls
{
[TemplatePart(Name = UniformGridTemplateName, Type = typeof(UniformGrid))]
- public class CropControl : Control
+ public class ImageCrop : Control
{
private const string UniformGridTemplateName = "PART_UniformGrid";
public static readonly DependencyProperty ImageSourceProperty =
- DependencyProperty.Register("ImageSource", typeof(ImageSource), typeof(CropControl),
+ DependencyProperty.Register("ImageSource", typeof(ImageSource), typeof(ImageCrop),
new PropertyMetadata(null));
public static readonly DependencyProperty RowColumnProperty =
- DependencyProperty.Register("RowColumn", typeof(int), typeof(CropControl), new PropertyMetadata(3));
+ DependencyProperty.Register("RowColumn", typeof(int), typeof(ImageCrop), new PropertyMetadata(3));
private UniformGrid _uniformGrid;
- static CropControl()
+ static ImageCrop()
{
- DefaultStyleKeyProperty.OverrideMetadata(typeof(CropControl),
- new FrameworkPropertyMetadata(typeof(CropControl)));
+ DefaultStyleKeyProperty.OverrideMetadata(typeof(ImageCrop),
+ new FrameworkPropertyMetadata(typeof(ImageCrop)));
}
public ImageSource ImageSource
diff --git a/src/WPFDevelopers.Samples.Shared/Controls/CropControl/CropControl.xaml b/src/WPFDevelopers.Samples.Shared/Controls/ImageCrop/ImageCrop.xaml
similarity index 73%
rename from src/WPFDevelopers.Samples.Shared/Controls/CropControl/CropControl.xaml
rename to src/WPFDevelopers.Samples.Shared/Controls/ImageCrop/ImageCrop.xaml
index b32dd3dd..fc7e4f5c 100644
--- a/src/WPFDevelopers.Samples.Shared/Controls/CropControl/CropControl.xaml
+++ b/src/WPFDevelopers.Samples.Shared/Controls/ImageCrop/ImageCrop.xaml
@@ -4,12 +4,12 @@
xmlns:controls="clr-namespace:WPFDevelopers.Samples.Controls"
xmlns:wd="https://github.com/WPFDevelopersOrg/WPFDevelopers">
-
+
\ No newline at end of file
diff --git a/src/WPFDevelopers.Samples.Shared/Controls/NavigateMenu/NavigateMenu.xaml b/src/WPFDevelopers.Samples.Shared/Controls/NavigateMenu/NavigateMenu.xaml
index eac27113..ff7252fa 100644
--- a/src/WPFDevelopers.Samples.Shared/Controls/NavigateMenu/NavigateMenu.xaml
+++ b/src/WPFDevelopers.Samples.Shared/Controls/NavigateMenu/NavigateMenu.xaml
@@ -20,6 +20,7 @@
Background="Transparent"
DisplayMemberPath="{Binding DisplayMemberPath, RelativeSource={RelativeSource AncestorType={x:Type controls:NavigateMenu}}}"
ItemsSource="{TemplateBinding ItemsSource}"
+ ItemTemplate="{Binding ItemTemplate, RelativeSource={RelativeSource AncestorType={x:Type controls:NavigateMenu}}}"
ScrollViewer.VerticalScrollBarVisibility="Hidden"
SelectedIndex="{Binding SelectedIndex, RelativeSource={RelativeSource AncestorType={x:Type controls:NavigateMenu}}}"
SelectedItem="{Binding SelectedItem, RelativeSource={RelativeSource AncestorType={x:Type controls:NavigateMenu}}}">
diff --git a/src/WPFDevelopers.Samples.Shared/Controls/Others/FireControl.cs b/src/WPFDevelopers.Samples.Shared/Controls/Others/Flame.cs
similarity index 67%
rename from src/WPFDevelopers.Samples.Shared/Controls/Others/FireControl.cs
rename to src/WPFDevelopers.Samples.Shared/Controls/Others/Flame.cs
index 71807744..74e857ec 100644
--- a/src/WPFDevelopers.Samples.Shared/Controls/Others/FireControl.cs
+++ b/src/WPFDevelopers.Samples.Shared/Controls/Others/Flame.cs
@@ -3,16 +3,16 @@
namespace WPFDevelopers.Samples.Controls
{
- public class FireControl : Control
+ public class Flame : Control
{
public static readonly DependencyProperty IsStartProperty =
- DependencyProperty.Register("IsStart", typeof(bool), typeof(FireControl),
+ DependencyProperty.Register("IsStart", typeof(bool), typeof(Flame),
new PropertyMetadata(default(bool)));
- static FireControl()
+ static Flame()
{
- DefaultStyleKeyProperty.OverrideMetadata(typeof(FireControl),
- new FrameworkPropertyMetadata(typeof(FireControl)));
+ DefaultStyleKeyProperty.OverrideMetadata(typeof(Flame),
+ new FrameworkPropertyMetadata(typeof(Flame)));
}
public bool IsStart
diff --git a/src/WPFDevelopers.Samples.Shared/Controls/Others/OtherControl.xaml b/src/WPFDevelopers.Samples.Shared/Controls/Others/Flame.xaml
similarity index 96%
rename from src/WPFDevelopers.Samples.Shared/Controls/Others/OtherControl.xaml
rename to src/WPFDevelopers.Samples.Shared/Controls/Others/Flame.xaml
index 3730e1a6..8f7159d1 100644
--- a/src/WPFDevelopers.Samples.Shared/Controls/Others/OtherControl.xaml
+++ b/src/WPFDevelopers.Samples.Shared/Controls/Others/Flame.xaml
@@ -4,16 +4,16 @@
xmlns:controls="clr-namespace:WPFDevelopers.Samples.Controls"
xmlns:wd="https://github.com/WPFDevelopersOrg/WPFDevelopers">
-
+
\ No newline at end of file
diff --git a/src/WPFDevelopers.Samples.Shared/Controls/PieControl/PieControl.cs b/src/WPFDevelopers.Samples.Shared/Controls/PieSegment/PieSegment.cs
similarity index 82%
rename from src/WPFDevelopers.Samples.Shared/Controls/PieControl/PieControl.cs
rename to src/WPFDevelopers.Samples.Shared/Controls/PieSegment/PieSegment.cs
index c2744da9..e15f795d 100644
--- a/src/WPFDevelopers.Samples.Shared/Controls/PieControl/PieControl.cs
+++ b/src/WPFDevelopers.Samples.Shared/Controls/PieSegment/PieSegment.cs
@@ -5,14 +5,14 @@
namespace WPFDevelopers.Samples.Controls
{
- public class PieControl : Control
+ public class PieSegment : Control
{
public static readonly DependencyProperty PieSegmentModelsProperty =
DependencyProperty.Register("PieSegmentModels", typeof(ObservableCollection),
- typeof(PieControl), new UIPropertyMetadata(OnPieSegmentModelChanged));
+ typeof(PieSegment), new UIPropertyMetadata(OnPieSegmentModelChanged));
public static readonly DependencyProperty ArcThicknessProperty =
- DependencyProperty.Register("ArcThickness", typeof(double), typeof(PieControl), new PropertyMetadata(1.0));
+ DependencyProperty.Register("ArcThickness", typeof(double), typeof(PieSegment), new PropertyMetadata(1.0));
///
/// colors
@@ -20,10 +20,10 @@ public class PieControl : Control
private readonly string[] ColorArray = { "#FDC006", "#607E89", "#2095F2", "#F34336" };
- static PieControl()
+ static PieSegment()
{
- DefaultStyleKeyProperty.OverrideMetadata(typeof(PieControl),
- new FrameworkPropertyMetadata(typeof(PieControl)));
+ DefaultStyleKeyProperty.OverrideMetadata(typeof(PieSegment),
+ new FrameworkPropertyMetadata(typeof(PieSegment)));
}
public ObservableCollection PieSegmentModels
@@ -44,7 +44,7 @@ public double ArcThickness
private static void OnPieSegmentModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
- var pieControl = d as PieControl;
+ var pieSegment = d as PieSegment;
if (e.NewValue != null)
{
var array = e.NewValue as ObservableCollection;
@@ -52,7 +52,7 @@ private static void OnPieSegmentModelChanged(DependencyObject d, DependencyPrope
foreach (var item in array)
{
var color = new SolidColorBrush(
- (Color)ColorConverter.ConvertFromString(pieControl.ColorArray[array.IndexOf(item)]));
+ (Color)ColorConverter.ConvertFromString(pieSegment.ColorArray[array.IndexOf(item)]));
item.Color = color;
item.StartAngle = angleNum;
item.EndAngle = angleNum + item.Value / 100 * 360;
diff --git a/src/WPFDevelopers.Samples.Shared/Controls/PieControl/PieControl.xaml b/src/WPFDevelopers.Samples.Shared/Controls/PieSegment/PieSegment.xaml
similarity index 91%
rename from src/WPFDevelopers.Samples.Shared/Controls/PieControl/PieControl.xaml
rename to src/WPFDevelopers.Samples.Shared/Controls/PieSegment/PieSegment.xaml
index b715112a..d9aefa6a 100644
--- a/src/WPFDevelopers.Samples.Shared/Controls/PieControl/PieControl.xaml
+++ b/src/WPFDevelopers.Samples.Shared/Controls/PieSegment/PieSegment.xaml
@@ -6,15 +6,15 @@
xmlns:wd="https://github.com/WPFDevelopersOrg/WPFDevelopers">
-
+
\ No newline at end of file
diff --git a/src/WPFDevelopers.Samples.Shared/Controls/PieControl/PieSegmentModel.cs b/src/WPFDevelopers.Samples.Shared/Controls/PieSegment/PieSegmentModel.cs
similarity index 100%
rename from src/WPFDevelopers.Samples.Shared/Controls/PieControl/PieSegmentModel.cs
rename to src/WPFDevelopers.Samples.Shared/Controls/PieSegment/PieSegmentModel.cs
diff --git a/src/WPFDevelopers.Samples.Shared/Controls/Theme/Theme.cs b/src/WPFDevelopers.Samples.Shared/Controls/Theme/Theme.cs
index 4813b5dd..9e48d243 100644
--- a/src/WPFDevelopers.Samples.Shared/Controls/Theme/Theme.cs
+++ b/src/WPFDevelopers.Samples.Shared/Controls/Theme/Theme.cs
@@ -8,6 +8,11 @@ namespace WPFDevelopers.Samples.Controls
{
public class Theme : ListBox
{
+ private static readonly DependencyProperty CurrentPrimaryColorProperty =
+ DependencyProperty.Register("CurrentPrimaryColor", typeof(Color), typeof(Theme),
+ new PropertyMetadata(default(Color), OnCurrentPrimaryColorChanged));
+
+ private bool _synchronizingSelection;
private readonly List themes = new List
{
@@ -49,7 +54,38 @@ public Theme()
});
}
ItemsSource = ThemeItems;
-
+ SetResourceReference(CurrentPrimaryColorProperty, "WD.PrimaryColor");
+ Loaded += (sender, e) => SynchronizeSelection();
+ }
+
+ private static void OnCurrentPrimaryColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ ((Theme)d).SynchronizeSelection();
+ }
+
+ private void SynchronizeSelection()
+ {
+ var color = (Color)GetValue(CurrentPrimaryColorProperty);
+ ThemeItem selectedItem = null;
+ foreach (var item in ThemeItems)
+ {
+ var brush = item.Background as SolidColorBrush;
+ if (brush != null && brush.Color == color)
+ {
+ selectedItem = item;
+ break;
+ }
+ }
+
+ _synchronizingSelection = true;
+ try
+ {
+ SelectedItem = selectedItem;
+ }
+ finally
+ {
+ _synchronizingSelection = false;
+ }
}
public override void OnApplyTemplate()
{
@@ -68,6 +104,7 @@ protected override DependencyObject GetContainerForItemOverride()
protected override void OnSelectionChanged(SelectionChangedEventArgs e)
{
base.OnSelectionChanged(e);
+ if (_synchronizingSelection) return;
if (SelectedItem == null) return;
var item = SelectedItem as ThemeItem;
if (item == null) return;
diff --git a/src/WPFDevelopers.Samples.Shared/Controls/TimeLine/TimeLine.cs b/src/WPFDevelopers.Samples.Shared/Controls/TimeLine/TimeLine.cs
deleted file mode 100644
index 927703e7..00000000
--- a/src/WPFDevelopers.Samples.Shared/Controls/TimeLine/TimeLine.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-using System.Windows;
-using System.Windows.Controls.Primitives;
-
-namespace WPFDevelopers.Samples.Controls
-{
- public class TimeLine : Selector
- {
- static TimeLine()
- {
- DefaultStyleKeyProperty.OverrideMetadata(typeof(TimeLine), new FrameworkPropertyMetadata(typeof(TimeLine)));
- }
- }
-}
\ No newline at end of file
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">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/ActivityFeedExample.xaml.cs b/src/WPFDevelopers.Samples.Shared/ExampleViews/ActivityFeedExample.xaml.cs
new file mode 100644
index 00000000..de7c87cf
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/ActivityFeedExample.xaml.cs
@@ -0,0 +1,68 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+using WPFDevelopers.Samples.Controls;
+
+namespace WPFDevelopers.Samples.ExampleViews
+{
+ ///
+ /// ActivityFeedExample.xaml 的交互逻辑
+ ///
+ public partial class ActivityFeedExample : UserControl
+ {
+ public ActivityFeedExample()
+ {
+ InitializeComponent();
+ }
+
+ int num = 0;
+ private void AddButton_Click(object sender, RoutedEventArgs e)
+ {
+ num++;
+ switch (num)
+ {
+ case 1:
+ this.Feed.Items.Add(new ActivityFeedItem() { Text = DateTime.Now.ToString("yyyy-MM-dd"), ItemType = ItemTypeEnum.Time });
+ this.Feed.Items.Add(new ActivityFeedItem() { Text = "我是骗人布010", Head = "我", ItemType = ItemTypeEnum.Name, BackgroundColor = new SolidColorBrush(GetRandomColor()) });
+ this.Feed.Items.Add(new ActivityFeedItem() { Text = "闫驚鏵/WPFDevelopers", ItemType = ItemTypeEnum.Star });
+ break;
+ case 2:
+ this.Feed.Items.Add(new ActivityFeedItem() { Text = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"), ItemType = ItemTypeEnum.Time });
+ this.Feed.Items.Add(new ActivityFeedItem() { Text = "风云大陆", Head = "风", ItemType = ItemTypeEnum.Name, BackgroundColor = new SolidColorBrush(GetRandomColor()) });
+ break;
+ case 3:
+ this.Feed.Items.Add(new ActivityFeedItem() { Text = DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd"), ItemType = ItemTypeEnum.Time });
+ this.Feed.Items.Add(new ActivityFeedItem() { Text = "王羲之", Head = "王", ItemType = ItemTypeEnum.Name, BackgroundColor = new SolidColorBrush(GetRandomColor()) });
+ this.Feed.Items.Add(new ActivityFeedItem() { Text = "闫驚鏵/WPFDevelopers", ItemType = ItemTypeEnum.Star });
+ break;
+ case 4:
+ this.Feed.Items.Add(new ActivityFeedItem() { Text = DateTime.Now.AddDays(-3).ToString("yyyy-MM-dd"), ItemType = ItemTypeEnum.Time });
+ this.Feed.Items.Add(new ActivityFeedItem() { Text = "花雨", Head = "花", ItemType = ItemTypeEnum.Name, BackgroundColor = new SolidColorBrush(GetRandomColor()) });
+ this.Feed.Items.Add(new ActivityFeedItem() { Text = "闫驚鏵/WPFDevelopers", ItemType = ItemTypeEnum.Star });
+ break;
+ case 5:
+ this.Feed.Items.Add(new ActivityFeedItem() { Text = DateTime.Now.AddDays(-6).ToString("yyyy-MM-dd"), ItemType = ItemTypeEnum.Time });
+ this.Feed.Items.Add(new ActivityFeedItem() { Text = "纪春庆", Head = "纪", ItemType = ItemTypeEnum.Name, BackgroundColor = new SolidColorBrush(GetRandomColor()) });
+ this.Feed.Items.Add(new ActivityFeedItem() { Text = "闫驚鏵/WPFDevelopers", ItemType = ItemTypeEnum.Star });
+ break;
+ default:
+ break;
+ }
+ }
+ Color GetRandomColor()
+ {
+ var random = new Random();
+ return Color.FromRgb((byte)random.Next(0, 255), (byte)random.Next(0, 255), (byte)random.Next(0, 255));
+ }
+ }
+}
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/BasicControlsExample.xaml b/src/WPFDevelopers.Samples.Shared/ExampleViews/BasicControlsExample.xaml
index a893dd8e..6a035d0f 100644
--- a/src/WPFDevelopers.Samples.Shared/ExampleViews/BasicControlsExample.xaml
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/BasicControlsExample.xaml
@@ -78,7 +78,7 @@
中文
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/Basics/DataGridExample.xaml b/src/WPFDevelopers.Samples.Shared/ExampleViews/Basics/DataGridExample.xaml
index bb394c0c..5271bdee 100644
--- a/src/WPFDevelopers.Samples.Shared/ExampleViews/Basics/DataGridExample.xaml
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/Basics/DataGridExample.xaml
@@ -13,6 +13,7 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/Basics/GridSplitterExample.xaml.cs b/src/WPFDevelopers.Samples.Shared/ExampleViews/Basics/GridSplitterExample.xaml.cs
new file mode 100644
index 00000000..146b6500
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/Basics/GridSplitterExample.xaml.cs
@@ -0,0 +1,12 @@
+using System.Windows.Controls;
+
+namespace WPFDevelopers.Samples.ExampleViews.Basics
+{
+ public partial class GridSplitterExample : UserControl
+ {
+ public GridSplitterExample()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/Basics/ListBoxExample.xaml b/src/WPFDevelopers.Samples.Shared/ExampleViews/Basics/ListBoxExample.xaml
index c52af3d4..9b6bcd70 100644
--- a/src/WPFDevelopers.Samples.Shared/ExampleViews/Basics/ListBoxExample.xaml
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/Basics/ListBoxExample.xaml
@@ -11,6 +11,7 @@
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/Basics/ListViewExample.xaml b/src/WPFDevelopers.Samples.Shared/ExampleViews/Basics/ListViewExample.xaml
index e8f39f6d..01c14ee6 100644
--- a/src/WPFDevelopers.Samples.Shared/ExampleViews/Basics/ListViewExample.xaml
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/Basics/ListViewExample.xaml
@@ -11,6 +11,7 @@
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/Basics/ThemeExample.xaml b/src/WPFDevelopers.Samples.Shared/ExampleViews/Basics/ThemeExample.xaml
index 640780d7..f48ed282 100644
--- a/src/WPFDevelopers.Samples.Shared/ExampleViews/Basics/ThemeExample.xaml
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/Basics/ThemeExample.xaml
@@ -89,7 +89,7 @@
中文
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/BubblleControlExample.xaml b/src/WPFDevelopers.Samples.Shared/ExampleViews/BubbleSelectionExample.xaml
similarity index 82%
rename from src/WPFDevelopers.Samples.Shared/ExampleViews/BubblleControlExample.xaml
rename to src/WPFDevelopers.Samples.Shared/ExampleViews/BubbleSelectionExample.xaml
index c5e229da..1ad85a60 100644
--- a/src/WPFDevelopers.Samples.Shared/ExampleViews/BubblleControlExample.xaml
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/BubbleSelectionExample.xaml
@@ -1,5 +1,5 @@
-
-
+
+
WPF
ASP.NET
@@ -28,11 +28,11 @@
WinForm
UWP
-
-
+
+
-
+
@@ -43,7 +43,7 @@
HorizontalAlignment="Center"
VerticalAlignment="Center">
-
+
-
-
+
+
+ Haader="BubbleSelection.cs" />
+ Haader="BubbleCanvas.cs" />
+ Haader="BubbleSelection.xaml" />
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/BubblleControlExample.xaml.cs b/src/WPFDevelopers.Samples.Shared/ExampleViews/BubbleSelectionExample.xaml.cs
similarity index 53%
rename from src/WPFDevelopers.Samples.Shared/ExampleViews/BubblleControlExample.xaml.cs
rename to src/WPFDevelopers.Samples.Shared/ExampleViews/BubbleSelectionExample.xaml.cs
index 9a5432f1..ad1a7d26 100644
--- a/src/WPFDevelopers.Samples.Shared/ExampleViews/BubblleControlExample.xaml.cs
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/BubbleSelectionExample.xaml.cs
@@ -6,11 +6,11 @@
namespace WPFDevelopers.Samples.ExampleViews
{
///
- /// BubbleControlExample.xaml 的交互逻辑
+ /// BubbleSelectionExample.xaml 的交互逻辑
///
- public partial class BubblleControlExample : UserControl
+ public partial class BubbleSelectionExample : UserControl
{
- public BubblleControlExample()
+ public BubbleSelectionExample()
{
InitializeComponent();
}
@@ -19,9 +19,9 @@ public BubblleControlExample()
WPFDevelopers.Controls.MessageBox.Show("点击完成。");
});
- private void BubblleControl_Click(object sender, System.Windows.RoutedEventArgs e)
+ private void BubbleSelection_Click(object sender, System.Windows.RoutedEventArgs e)
{
- MessageBox.Show($"点击了“ {MyBubblleControl.SelectedText}开发者 ”.", "提示",MessageBoxButton.OK,MessageBoxImage.Information);
+ MessageBox.Show($"点击了“ {MyBubbleSelection.SelectedText}开发者 ”.", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
}
}
}
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/ColorPickerExample.xaml b/src/WPFDevelopers.Samples.Shared/ExampleViews/ColorPickerExample.xaml
index ada5c56f..861446d8 100644
--- a/src/WPFDevelopers.Samples.Shared/ExampleViews/ColorPickerExample.xaml
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/ColorPickerExample.xaml
@@ -11,7 +11,48 @@
d:DesignWidth="800"
mc:Ignorable="d">
-
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/DateRangePickerExample.xaml b/src/WPFDevelopers.Samples.Shared/ExampleViews/DateRangePickerExample.xaml
index c29908fe..293175fd 100644
--- a/src/WPFDevelopers.Samples.Shared/ExampleViews/DateRangePickerExample.xaml
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/DateRangePickerExample.xaml
@@ -24,7 +24,7 @@
wd:ElementHelper.CornerRadius="3"
EndWatermark="EndDate"
StartWatermark="StartDate" />
-
+
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/OtherControlExample.xaml b/src/WPFDevelopers.Samples.Shared/ExampleViews/FlameExample.xaml
similarity index 89%
rename from src/WPFDevelopers.Samples.Shared/ExampleViews/OtherControlExample.xaml
rename to src/WPFDevelopers.Samples.Shared/ExampleViews/FlameExample.xaml
index a95a066b..df79221a 100644
--- a/src/WPFDevelopers.Samples.Shared/ExampleViews/OtherControlExample.xaml
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/FlameExample.xaml
@@ -1,5 +1,5 @@
-
-
-
+
+
+ Haader="Flame.xaml" />
+ Haader="Flame.cs" />
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/CropControlExample.xaml.cs b/src/WPFDevelopers.Samples.Shared/ExampleViews/FlameExample.xaml.cs
similarity index 56%
rename from src/WPFDevelopers.Samples.Shared/ExampleViews/CropControlExample.xaml.cs
rename to src/WPFDevelopers.Samples.Shared/ExampleViews/FlameExample.xaml.cs
index 16ba9479..4197fb40 100644
--- a/src/WPFDevelopers.Samples.Shared/ExampleViews/CropControlExample.xaml.cs
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/FlameExample.xaml.cs
@@ -3,11 +3,11 @@
namespace WPFDevelopers.Samples.ExampleViews
{
///
- /// CropControlExample.xaml 的交互逻辑
+ /// Interaction logic for FlameExample.xaml
///
- public partial class CropControlExample : UserControl
+ public partial class FlameExample : UserControl
{
- public CropControlExample()
+ public FlameExample()
{
InitializeComponent();
}
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/GestureUnlockExample.xaml b/src/WPFDevelopers.Samples.Shared/ExampleViews/GestureUnlockExample.xaml
index a84ccb03..906ddcd2 100644
--- a/src/WPFDevelopers.Samples.Shared/ExampleViews/GestureUnlockExample.xaml
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/GestureUnlockExample.xaml
@@ -13,14 +13,17 @@
-
-
-
-
-
+
+
+
+
+
+
+
+
@@ -28,16 +31,19 @@
-
-
-
-
-
+
+
+
+
+
+
+
+
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/HomeExample.xaml b/src/WPFDevelopers.Samples.Shared/ExampleViews/HomeExample.xaml
new file mode 100644
index 00000000..0c01d99d
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/HomeExample.xaml
@@ -0,0 +1,274 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
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/CropControlExample.xaml b/src/WPFDevelopers.Samples.Shared/ExampleViews/ImageCropExample.xaml
similarity index 67%
rename from src/WPFDevelopers.Samples.Shared/ExampleViews/CropControlExample.xaml
rename to src/WPFDevelopers.Samples.Shared/ExampleViews/ImageCropExample.xaml
index b70ccb68..fba9a81d 100644
--- a/src/WPFDevelopers.Samples.Shared/ExampleViews/CropControlExample.xaml
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/ImageCropExample.xaml
@@ -1,5 +1,5 @@
-
+
-
-
+
+
+ Haader="ImageCrop.xaml" />
+ Haader="ImageCrop.cs" />
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/RulerControlExample.xaml.cs b/src/WPFDevelopers.Samples.Shared/ExampleViews/ImageCropExample.xaml.cs
similarity index 56%
rename from src/WPFDevelopers.Samples.Shared/ExampleViews/RulerControlExample.xaml.cs
rename to src/WPFDevelopers.Samples.Shared/ExampleViews/ImageCropExample.xaml.cs
index 9decfc70..49592109 100644
--- a/src/WPFDevelopers.Samples.Shared/ExampleViews/RulerControlExample.xaml.cs
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/ImageCropExample.xaml.cs
@@ -3,11 +3,11 @@
namespace WPFDevelopers.Samples.ExampleViews
{
///
- /// RulerControlExample.xaml 的交互逻辑
+ /// ImageCropExample.xaml 的交互逻辑
///
- public partial class RulerControlExample : UserControl
+ public partial class ImageCropExample : UserControl
{
- public RulerControlExample()
+ public ImageCropExample()
{
InitializeComponent();
}
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/MainWindow.xaml b/src/WPFDevelopers.Samples.Shared/ExampleViews/MainWindow.xaml
index 808ceea5..9d25d8a3 100644
--- a/src/WPFDevelopers.Samples.Shared/ExampleViews/MainWindow.xaml
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/MainWindow.xaml
@@ -24,6 +24,31 @@
HorizontalAlignment="Right"
wd:PanelHelper.Spacing="2"
Orientation="Horizontal">
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -149,35 +175,119 @@
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+ ItemsSource="{Binding NavigateMenuModelList}"
+ SelectedItem="{Binding NavigateMenuItem, Mode=TwoWay}">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -188,6 +298,7 @@
@@ -195,7 +306,6 @@
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/MainWindow.xaml.cs b/src/WPFDevelopers.Samples.Shared/ExampleViews/MainWindow.xaml.cs
index c5175b3b..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;
@@ -21,6 +22,7 @@ public partial class MainWindow
public MainWindow()
{
InitializeComponent();
+ VersionText.Text = "v" + typeof(MainWindow).BaseType.Assembly.GetName().Version.ToString(3);
Loaded += OnMainWindow_Loaded;
Closing += MainWindow_Closing;
}
@@ -33,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;
@@ -56,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/ExampleViews/MaskExample.xaml.cs b/src/WPFDevelopers.Samples.Shared/ExampleViews/MaskExample.xaml.cs
index bb0f0113..eca20909 100644
--- a/src/WPFDevelopers.Samples.Shared/ExampleViews/MaskExample.xaml.cs
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/MaskExample.xaml.cs
@@ -15,12 +15,12 @@ public MaskExample()
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
- new AboutWindow().MaskShowDialog();
+ new AboutWindow { Owner = System.Windows.Window.GetWindow(this) }.MaskShowDialog();
}
private void Button_Click_1(object sender, System.Windows.RoutedEventArgs e)
{
- new AboutWindow().MaskShow();
+ new AboutWindow { Owner = System.Windows.Window.GetWindow(this) }.MaskShow();
}
}
}
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/OtherControlExample.xaml.cs b/src/WPFDevelopers.Samples.Shared/ExampleViews/OtherControlExample.xaml.cs
deleted file mode 100644
index 892c8f94..00000000
--- a/src/WPFDevelopers.Samples.Shared/ExampleViews/OtherControlExample.xaml.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
-
-namespace WPFDevelopers.Samples.ExampleViews
-{
- ///
- /// Interaction logic for OtherControlExample.xaml
- ///
- public partial class OtherControlExample : UserControl
- {
- public OtherControlExample()
- {
- InitializeComponent();
- }
- }
-}
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/PieControlExample.xaml b/src/WPFDevelopers.Samples.Shared/ExampleViews/PieSegmentExample.xaml
similarity index 75%
rename from src/WPFDevelopers.Samples.Shared/ExampleViews/PieControlExample.xaml
rename to src/WPFDevelopers.Samples.Shared/ExampleViews/PieSegmentExample.xaml
index d2505115..555c99a8 100644
--- a/src/WPFDevelopers.Samples.Shared/ExampleViews/PieControlExample.xaml
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/PieSegmentExample.xaml
@@ -1,5 +1,5 @@
-
-
+
-
+ PieSegmentModels="{Binding PieSegmentModels, RelativeSource={RelativeSource AncestorType=local:PieSegmentExample}}" />
+
-
-
+
+
+ Haader="PieSegment.xaml" />
+ Haader="PieSegment.cs" />
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/PieControlExample.xaml.cs b/src/WPFDevelopers.Samples.Shared/ExampleViews/PieSegmentExample.xaml.cs
similarity index 91%
rename from src/WPFDevelopers.Samples.Shared/ExampleViews/PieControlExample.xaml.cs
rename to src/WPFDevelopers.Samples.Shared/ExampleViews/PieSegmentExample.xaml.cs
index 01b5bbba..5edd0dc4 100644
--- a/src/WPFDevelopers.Samples.Shared/ExampleViews/PieControlExample.xaml.cs
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/PieSegmentExample.xaml.cs
@@ -7,9 +7,9 @@
namespace WPFDevelopers.Samples.ExampleViews
{
///
- /// PieControlExample.xaml 的交互逻辑
+ /// PieSegmentExample.xaml 的交互逻辑
///
- public partial class PieControlExample : UserControl
+ public partial class PieSegmentExample : UserControl
{
public ObservableCollection PieSegmentModels
{
@@ -18,10 +18,10 @@ public ObservableCollection PieSegmentModels
}
public static readonly DependencyProperty PieSegmentModelsProperty =
- DependencyProperty.Register("PieSegmentModels", typeof(ObservableCollection), typeof(PieControlExample), new PropertyMetadata(null));
+ DependencyProperty.Register("PieSegmentModels", typeof(ObservableCollection), typeof(PieSegmentExample), new PropertyMetadata(null));
List> collectionList = new List>();
- public PieControlExample()
+ public PieSegmentExample()
{
InitializeComponent();
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/RulerControlExample.xaml b/src/WPFDevelopers.Samples.Shared/ExampleViews/RulerExample.xaml
similarity index 94%
rename from src/WPFDevelopers.Samples.Shared/ExampleViews/RulerControlExample.xaml
rename to src/WPFDevelopers.Samples.Shared/ExampleViews/RulerExample.xaml
index 7deb39e9..88fd2322 100644
--- a/src/WPFDevelopers.Samples.Shared/ExampleViews/RulerControlExample.xaml
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/RulerExample.xaml
@@ -1,5 +1,5 @@
-
-
+
+
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/RulerExample.xaml.cs b/src/WPFDevelopers.Samples.Shared/ExampleViews/RulerExample.xaml.cs
new file mode 100644
index 00000000..b785f122
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/RulerExample.xaml.cs
@@ -0,0 +1,15 @@
+using System.Windows.Controls;
+
+namespace WPFDevelopers.Samples.ExampleViews
+{
+ ///
+ /// RulerExample.xaml 的交互逻辑
+ ///
+ public partial class RulerExample : UserControl
+ {
+ public RulerExample()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/ScrollNavigationExample.xaml b/src/WPFDevelopers.Samples.Shared/ExampleViews/ScrollNavigationExample.xaml
new file mode 100644
index 00000000..36985c67
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/ScrollNavigationExample.xaml
@@ -0,0 +1,70 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/ScrollNavigationExample.xaml.cs b/src/WPFDevelopers.Samples.Shared/ExampleViews/ScrollNavigationExample.xaml.cs
new file mode 100644
index 00000000..c0796688
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/ScrollNavigationExample.xaml.cs
@@ -0,0 +1,12 @@
+using System.Windows.Controls;
+
+namespace WPFDevelopers.Samples.ExampleViews
+{
+ public partial class ScrollNavigationExample : UserControl
+ {
+ public ScrollNavigationExample()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/ScrollViewerAnimationExample.xaml b/src/WPFDevelopers.Samples.Shared/ExampleViews/ScrollViewerAnimationExample.xaml
index 391c2f19..eebc697a 100644
--- a/src/WPFDevelopers.Samples.Shared/ExampleViews/ScrollViewerAnimationExample.xaml
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/ScrollViewerAnimationExample.xaml
@@ -15,7 +15,10 @@
-
+
@@ -46,7 +49,8 @@
+ IsScrollAnimation="True"
+ wd:ScrollViewerBehavior.IsBackToTopEnabled="True">
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/SpacingExample.xaml b/src/WPFDevelopers.Samples.Shared/ExampleViews/SpacingExample.xaml
index 3b77df6f..c67c0327 100644
--- a/src/WPFDevelopers.Samples.Shared/ExampleViews/SpacingExample.xaml
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/SpacingExample.xaml
@@ -26,10 +26,17 @@
Height="40"
Padding="20,0"
Header="WrapPanel">
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/TimeLineExample.xaml b/src/WPFDevelopers.Samples.Shared/ExampleViews/TimeLineExample.xaml
index e7c5f0e7..3a3123b9 100644
--- a/src/WPFDevelopers.Samples.Shared/ExampleViews/TimeLineExample.xaml
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/TimeLineExample.xaml
@@ -1,44 +1,182 @@
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
+ Haader="TimelineExampleVM.cs" />
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/TimeLineExample.xaml.cs b/src/WPFDevelopers.Samples.Shared/ExampleViews/TimeLineExample.xaml.cs
index df8b4fbc..9578df27 100644
--- a/src/WPFDevelopers.Samples.Shared/ExampleViews/TimeLineExample.xaml.cs
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/TimeLineExample.xaml.cs
@@ -1,68 +1,100 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
+using System;
+using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
-using WPFDevelopers.Samples.Controls;
+using WPFDevelopers.Controls;
+using WPFDevelopers.Samples.ViewModels;
namespace WPFDevelopers.Samples.ExampleViews
{
- ///
- /// TimeLineExample.xaml 的交互逻辑
- ///
- public partial class TimeLineExample : UserControl
+ public partial class TimelineExample : UserControl
{
- public TimeLineExample()
+ private int _eventNumber;
+
+ public ObservableCollection CodeEvents { get; private set; }
+ public Array Orientations { get; private set; }
+ public Array Modes { get; private set; }
+
+ public TimelineExample()
{
+ CodeEvents = new ObservableCollection();
+ Orientations = Enum.GetValues(typeof(Orientation));
+ Modes = Enum.GetValues(typeof(TimelineMode));
+ ResetEvents();
InitializeComponent();
}
- int num = 0;
- private void AddButton_Click(object sender, RoutedEventArgs e)
+ private void Add_Click(object sender, RoutedEventArgs e)
{
- num++;
- switch (num)
+ AddEvent();
+ }
+
+ private void Next_Click(object sender, RoutedEventArgs e)
+ {
+ CompleteEvents(false);
+ AddEvent(true);
+ }
+
+ private void AddEvent(bool isLoading = false)
+ {
+ CodeEvents.Add(new TimelineEvent
{
- case 1:
- this.TimeLine.Items.Add(new TimeLineItem() { Text = DateTime.Now.ToString("yyyy-MM-dd"), ItemType = ItemTypeEnum.Time });
- this.TimeLine.Items.Add(new TimeLineItem() { Text = "我是骗人布010", Head = "我", ItemType = ItemTypeEnum.Name, BackgroundColor = new SolidColorBrush(GetRandomColor()) });
- this.TimeLine.Items.Add(new TimeLineItem() { Text = "闫驚鏵/WPFDevelopers", ItemType = ItemTypeEnum.Star });
- break;
- case 2:
- this.TimeLine.Items.Add(new TimeLineItem() { Text = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"), ItemType = ItemTypeEnum.Time });
- this.TimeLine.Items.Add(new TimeLineItem() { Text = "风云大陆", Head = "风", ItemType = ItemTypeEnum.Name, BackgroundColor = new SolidColorBrush(GetRandomColor()) });
- break;
- case 3:
- this.TimeLine.Items.Add(new TimeLineItem() { Text = DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd"), ItemType = ItemTypeEnum.Time });
- this.TimeLine.Items.Add(new TimeLineItem() { Text = "王羲之", Head = "王", ItemType = ItemTypeEnum.Name, BackgroundColor = new SolidColorBrush(GetRandomColor()) });
- this.TimeLine.Items.Add(new TimeLineItem() { Text = "闫驚鏵/WPFDevelopers", ItemType = ItemTypeEnum.Star });
- break;
- case 4:
- this.TimeLine.Items.Add(new TimeLineItem() { Text = DateTime.Now.AddDays(-3).ToString("yyyy-MM-dd"), ItemType = ItemTypeEnum.Time });
- this.TimeLine.Items.Add(new TimeLineItem() { Text = "花雨", Head = "花", ItemType = ItemTypeEnum.Name, BackgroundColor = new SolidColorBrush(GetRandomColor()) });
- this.TimeLine.Items.Add(new TimeLineItem() { Text = "闫驚鏵/WPFDevelopers", ItemType = ItemTypeEnum.Star });
- break;
- case 5:
- this.TimeLine.Items.Add(new TimeLineItem() { Text = DateTime.Now.AddDays(-6).ToString("yyyy-MM-dd"), ItemType = ItemTypeEnum.Time });
- this.TimeLine.Items.Add(new TimeLineItem() { Text = "纪春庆", Head = "纪", ItemType = ItemTypeEnum.Name, BackgroundColor = new SolidColorBrush(GetRandomColor()) });
- this.TimeLine.Items.Add(new TimeLineItem() { Text = "闫驚鏵/WPFDevelopers", ItemType = ItemTypeEnum.Star });
- break;
- default:
- break;
+ Time = DateTime.Now.ToString("HH:mm:ss"),
+ Title = "Event " + ++_eventNumber,
+ Description = "Added by a C# click event.",
+ Brush = Brushes.DodgerBlue,
+ IsLoading = isLoading
+ });
+ }
+
+ private void Remove_Click(object sender, RoutedEventArgs e)
+ {
+ if (CodeEvents.Count > 0) CodeEvents.RemoveAt(CodeEvents.Count - 1);
+ }
+
+ private void Complete_Click(object sender, RoutedEventArgs e)
+ {
+ CompleteEvents(true);
+ }
+
+ private void CompleteEvents(bool onlyLoading)
+ {
+ foreach (var item in CodeEvents)
+ {
+ if (onlyLoading && !item.IsLoading) continue;
+ item.IsLoading = false;
+ item.Title = "Completed";
+ item.Description = "Updated by a C# click event.";
+ item.Brush = Brushes.SeaGreen;
}
}
- Color GetRandomColor()
+
+ private void Reset_Click(object sender, RoutedEventArgs e)
+ {
+ ResetEvents();
+ }
+
+ private void ResetEvents()
{
- var random = new Random();
- return Color.FromRgb((byte)random.Next(0, 255), (byte)random.Next(0, 255), (byte)random.Next(0, 255));
+ CodeEvents.Clear();
+ _eventNumber = 3;
+ CodeEvents.Add(new TimelineEvent
+ {
+ Time = "09:00", Title = "Created",
+ Description = "Create a service site.", Brush = Brushes.DodgerBlue
+ });
+ CodeEvents.Add(new TimelineEvent
+ {
+ Time = "10:00", Title = "Completed",
+ Description = "Solve initial network problems.", Brush = Brushes.SeaGreen
+ });
+ CodeEvents.Add(new TimelineEvent
+ {
+ Time = "11:00", Title = "In progress",
+ Description = "Technical testing is in progress.", Brush = Brushes.DodgerBlue,
+ IsLoading = true
+ });
}
}
}
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/TimePickerExample.xaml b/src/WPFDevelopers.Samples.Shared/ExampleViews/TimePickerExample.xaml
index 8a26e557..185c14ee 100644
--- a/src/WPFDevelopers.Samples.Shared/ExampleViews/TimePickerExample.xaml
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/TimePickerExample.xaml
@@ -24,12 +24,20 @@
Width="200"
VerticalAlignment="Center"
wd:ElementHelper.Watermark="selection time"
- SelectedTime="2023-05-06 23:59:59" />
+ SelectedTime="2023-05-06 23:59:59"
+ SelectedTimeFormat="HH:mm" />
+
+ SelectedTime="{Binding MyDateTime, RelativeSource={RelativeSource AncestorType=local:TimePickerExample}}"
+ SelectedTimeFormat="hh:mm tt" />
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/VirtualizingWrapPanelExample.xaml b/src/WPFDevelopers.Samples.Shared/ExampleViews/VirtualizingWrapPanelExample.xaml
index 99452bc9..1e4d5402 100644
--- a/src/WPFDevelopers.Samples.Shared/ExampleViews/VirtualizingWrapPanelExample.xaml
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/VirtualizingWrapPanelExample.xaml
@@ -1,119 +1,156 @@
-
+
-
-
+
+
-
+
-
+
-
+
-
+
-
+
-
+
-
-
-
+
+
+
-
+
-
+
-
-
+
+
-
-
-
+
+
+
-
+
-
+
-
+
-
-
-
+
+
+
-
-
+
+
-
+
-
+
-
+
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/WaterfallPanelExample.xaml b/src/WPFDevelopers.Samples.Shared/ExampleViews/WaterfallPanelExample.xaml
index 2989454b..46cdef80 100644
--- a/src/WPFDevelopers.Samples.Shared/ExampleViews/WaterfallPanelExample.xaml
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/WaterfallPanelExample.xaml
@@ -4,144 +4,95 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:WPFDevelopers.Samples.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:local="clr-namespace:WPFDevelopers.Samples.ExampleViews"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:vm="clr-namespace:WPFDevelopers.Samples.ViewModels"
xmlns:wd="https://github.com/WPFDevelopersOrg/WPFDevelopers"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/WaterfallPanelExample.xaml.cs b/src/WPFDevelopers.Samples.Shared/ExampleViews/WaterfallPanelExample.xaml.cs
index c649bcfb..3850b4e1 100644
--- a/src/WPFDevelopers.Samples.Shared/ExampleViews/WaterfallPanelExample.xaml.cs
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/WaterfallPanelExample.xaml.cs
@@ -1,4 +1,6 @@
-using System.Windows.Controls;
+using System.Diagnostics;
+using System.Windows;
+using System.Windows.Controls;
namespace WPFDevelopers.Samples.ExampleViews
{
@@ -7,9 +9,22 @@ namespace WPFDevelopers.Samples.ExampleViews
///
public partial class WaterfallPanelExample : UserControl
{
+ private bool _imageFailureReported;
+
public WaterfallPanelExample()
{
InitializeComponent();
}
+
+ private void Image_Failed(object sender, ExceptionRoutedEventArgs e)
+ {
+ Debug.WriteLine("[Waterfall] Image failed: " + e.ErrorException);
+ if (_imageFailureReported)
+ return;
+
+ _imageFailureReported = true;
+ WPFDevelopers.Controls.MessageBox.Show(e.ErrorException.ToString(),
+ "Waterfall image loading failed");
+ }
}
}
diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/Window/WindowExample.xaml b/src/WPFDevelopers.Samples.Shared/ExampleViews/Window/WindowExample.xaml
index a21a5076..9dc82f30 100644
--- a/src/WPFDevelopers.Samples.Shared/ExampleViews/Window/WindowExample.xaml
+++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/Window/WindowExample.xaml
@@ -20,13 +20,11 @@
Rows="2">
ChineseNames = new Dictionary
+ {
+ [MenuEnum.NavMenu3D] = "三维导航菜单",
+ [MenuEnum.UsageGuide] = "使用指南",
+ [MenuEnum.UsageColor] = "色彩指南",
+ [MenuEnum.MessageBox] = "消息框",
+ [MenuEnum.NotifyIcon] = "托盘图标",
+ [MenuEnum.PanningItems] = "平移列表",
+ [MenuEnum.BreatheLight] = "呼吸灯",
+ [MenuEnum.RingLoading] = "环形加载动画",
+ [MenuEnum.BallLoading] = "球形加载动画",
+ [MenuEnum.StreamerLoading] = "流光加载动画",
+ [MenuEnum.WaitLoading] = "等待加载",
+ [MenuEnum.CycleLoading] = "循环加载",
+ [MenuEnum.RollLoading] = "滚动加载",
+ [MenuEnum.CropAvatar] = "头像裁剪",
+ [MenuEnum.AnimationAudio] = "音频动画",
+ [MenuEnum.TransformLayout] = "变换布局",
+ [MenuEnum.VerifyCode] = "验证码",
+ [MenuEnum.CircleMenu] = "圆形菜单",
+ [MenuEnum.ChatEmoji] = "聊天表情",
+ [MenuEnum.CircleProgressBar] = "圆形进度条",
+ [MenuEnum.Dashboard] = "仪表盘",
+ [MenuEnum.PieSegment] = "分段饼图",
+ [MenuEnum.Password] = "密码框",
+ [MenuEnum.SongWords] = "歌词",
+ [MenuEnum.Timeline] = "时间轴",
+ [MenuEnum.ActivityFeed] = "活动记录(示例控件)",
+ [MenuEnum.CardCarousel] = "卡片轮播",
+ [MenuEnum.FocusCarousel] = "聚焦轮播",
+ [MenuEnum.Pagination] = "分页",
+ [MenuEnum.ScrollViewer] = "滚动视图",
+ [MenuEnum.ScrollNavigation] = "滚动导航",
+ [MenuEnum.Flame] = "火苗",
+ [MenuEnum.ScreenCut] = "屏幕截图",
+ [MenuEnum.TransitionPanel] = "过渡面板",
+ [MenuEnum.SpotLight] = "聚光灯",
+ [MenuEnum.DrawerMenu] = "抽屉菜单",
+ [MenuEnum.ChartRadar] = "雷达图",
+ [MenuEnum.ChartBar] = "柱状图",
+ [MenuEnum.ZooSemy] = "拟物音量调节",
+ [MenuEnum.Ruler] = "标尺控件",
+ [MenuEnum.RainbowBtn] = "彩虹按钮",
+ [MenuEnum.RoundPicker] = "圆形选择器",
+ [MenuEnum.LineChart] = "折线图",
+ [MenuEnum.Thermometer] = "温度计",
+ [MenuEnum.SnowCanvas] = "雪花画布",
+ [MenuEnum.LoginWindow] = "登录窗口",
+ [MenuEnum.Drawing] = "绘图",
+ [MenuEnum.SpeedRockets] = "火箭动画",
+ [MenuEnum.CountdownTimer] = "倒计时",
+ [MenuEnum.NumberCard] = "数字卡片",
+ [MenuEnum.ImageCrop] = "图片裁剪",
+ [MenuEnum.Desktop] = "桌面背景",
+ [MenuEnum.DrawPrize] = "抽奖",
+ [MenuEnum.EdgeLight] = "边缘光",
+ [MenuEnum.StarrySky] = "星空",
+ [MenuEnum.Shake] = "抖动",
+ [MenuEnum.BubbleSelection] = "气泡选择",
+ [MenuEnum.CanvasHandWriting] = "手写画布",
+ [MenuEnum.Barrage] = "弹幕",
+ [MenuEnum.SixGridView] = "六宫格",
+ [MenuEnum.Magnifier] = "放大镜",
+ [MenuEnum.Step] = "步骤条",
+ [MenuEnum.MultiSelectComboBox] = "多选下拉框(带搜索)",
+ [MenuEnum.Mask] = "遮罩",
+ [MenuEnum.Loading] = "加载动画",
+ [MenuEnum.Selector] = "列表定位",
+ //[MenuEnum.MultiSelectSearchComboBox] = "示例多选下拉框",
+ [MenuEnum.BreadCrumbBar] = "面包屑导航",
+ [MenuEnum.CropImage] = "图片裁剪",
+ [MenuEnum.Badge] = "徽标",
+ [MenuEnum.Toast] = "消息提示",
+ [MenuEnum.PathIcon] = "路径图标",
+ [MenuEnum.NumericBox] = "数字输入框",
+ [MenuEnum.ColorPicker] = "颜色选择器",
+ [MenuEnum.IPEditBox] = "IP 地址输入框",
+ [MenuEnum.TimePicker] = "时间选择器",
+ [MenuEnum.WaterfallPanel] = "瀑布流",
+ [MenuEnum.ChartLine] = "折线图",
+ [MenuEnum.Drap] = "拖拽",
+ [MenuEnum.ChartPie] = "饼图",
+ [MenuEnum.Spacing] = "布局间距",
+ [MenuEnum.Drawer] = "抽屉",
+ [MenuEnum.DateRangePicker] = "日期范围选择器",
+ [MenuEnum.Gauge] = "仪表",
+ [MenuEnum.Tag] = "标签",
+ [MenuEnum.NavScrollPanel] = "导航滚动面板",
+ [MenuEnum.IconicThumbnail] = "任务栏缩略图",
+ [MenuEnum.GestureUnlock] = "手势解锁",
+ [MenuEnum.AnimationGrid] = "动画网格",
+ [MenuEnum.AllPathIcon] = "图标库",
+ [MenuEnum.Dial] = "拨盘",
+ [MenuEnum.SvgViewer] = "SVG 查看器",
+ [MenuEnum.DataGridFilter] = "数据表格筛选",
+ [MenuEnum.GrayscaleEffect] = "灰度效果",
+ [MenuEnum.OtpBox] = "一次性验证码输入框",
+ [MenuEnum.Carousel] = "走马灯",
+ [MenuEnum.SplitButton] = "分割按钮",
+ [MenuEnum.Segmented] = "分段选择器",
+ [MenuEnum.MarkdownViewer] = "Markdown 查看器",
+ [MenuEnum.MapView] = "地图",
+ [MenuEnum.VirtualizingWrapPanel] = "虚拟化换行面板",
+ [MenuEnum.AcrylicBlur] = "亚克力效果",
+ [MenuEnum.Theme] = "主题",
+ [MenuEnum.Menu] = "菜单",
+ [MenuEnum.Window] = "窗口",
+ [MenuEnum.BasicLoading] = "基础加载动画",
+ [MenuEnum.Button] = "按钮",
+ [MenuEnum.RadioButton] = "单选按钮",
+ [MenuEnum.Checkbox] = "复选框",
+ [MenuEnum.TextBox] = "文本框",
+ [MenuEnum.PasswordBox] = "密码框",
+ [MenuEnum.ComboBox] = "下拉框",
+ [MenuEnum.ToggleButton] = "切换按钮",
+ [MenuEnum.DatePicker] = "日期选择器",
+ [MenuEnum.DateTimePicker] = "日期时间选择器",
+ [MenuEnum.Calendar] = "日历",
+ [MenuEnum.Slider] = "滑块",
+ [MenuEnum.GridSplitter] = "网格分隔条",
+ [MenuEnum.ProgressBar] = "进度条",
+ [MenuEnum.DataGrid] = "数据表格",
+ [MenuEnum.ListBox] = "列表框",
+ [MenuEnum.ListView] = "列表视图",
+ [MenuEnum.TreeView] = "树视图",
+ [MenuEnum.Expander] = "折叠面板",
+ [MenuEnum.GroupBox] = "分组框",
+ [MenuEnum.TabControl] = "选项卡",
+ [MenuEnum.TaskbarInfo] = "任务栏信息"
+ };
+
+ public static string GetDisplayName(string name, CultureInfo culture)
+ {
+ if (name == "持续更新中")
+ return culture.TwoLetterISOLanguageName == "zh" ? name : "More updates coming";
+
+ if (culture.TwoLetterISOLanguageName != "zh" ||
+ !Enum.TryParse(name, out MenuEnum menu) ||
+ !ChineseNames.TryGetValue(menu, out var chineseName))
+ return name;
+
+ return chineseName;
+ }
+ }
+}
diff --git a/src/WPFDevelopers.Samples.Shared/Models/NavigateMenuModel.cs b/src/WPFDevelopers.Samples.Shared/Models/NavigateMenuModel.cs
index eaa3dae6..90b3023d 100644
--- a/src/WPFDevelopers.Samples.Shared/Models/NavigateMenuModel.cs
+++ b/src/WPFDevelopers.Samples.Shared/Models/NavigateMenuModel.cs
@@ -3,7 +3,23 @@
public class NavigateMenuModel:ViewModelBase
{
private bool _isVisible = true;
+ private string _displayName;
+ private string _changeType = string.Empty;
+ public bool IsDemo { get; set; }
public string Name { get; set; }
+ public string IconSource { get; set; }
+ public string DisplayName
+ {
+ get { return _displayName; }
+ set { SetProperty(ref _displayName, value, nameof(DisplayName)); }
+ }
+
+ public string ChangeType
+ {
+ get { return _changeType; }
+ set { SetProperty(ref _changeType, value, nameof(ChangeType)); }
+ }
+
public bool IsVisible
{
get { return _isVisible; }
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/Assets/wxgzh.jpg b/src/WPFDevelopers.Samples.Shared/Resources/Assets/wxgzh.jpg
new file mode 100644
index 00000000..dfb32544
Binary files /dev/null and b/src/WPFDevelopers.Samples.Shared/Resources/Assets/wxgzh.jpg differ
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Activity.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Activity.svg
new file mode 100644
index 00000000..5ff0040d
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Activity.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Animal.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Animal.svg
new file mode 100644
index 00000000..b28119b2
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Animal.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Book.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Book.svg
new file mode 100644
index 00000000..16285f5d
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Book.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Button.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Button.svg
new file mode 100644
index 00000000..6cd39553
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Button.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Calendar.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Calendar.svg
new file mode 100644
index 00000000..52b559bc
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Calendar.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Cards.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Cards.svg
new file mode 100644
index 00000000..36879621
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Cards.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Chart.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Chart.svg
new file mode 100644
index 00000000..3ce955ca
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Chart.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Chat.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Chat.svg
new file mode 100644
index 00000000..69580ed9
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Chat.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Checkbox.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Checkbox.svg
new file mode 100644
index 00000000..7f81cdd7
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Checkbox.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Circle.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Circle.svg
new file mode 100644
index 00000000..a1523aa9
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Circle.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/ComboBox.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/ComboBox.svg
new file mode 100644
index 00000000..e5e984d4
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/ComboBox.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Crop.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Crop.svg
new file mode 100644
index 00000000..59422d71
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Crop.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Dashboard.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Dashboard.svg
new file mode 100644
index 00000000..c22de4a6
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Dashboard.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/DataGrid.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/DataGrid.svg
new file mode 100644
index 00000000..8410bbec
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/DataGrid.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/DatePicker.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/DatePicker.svg
new file mode 100644
index 00000000..54c60b35
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/DatePicker.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/DateTimePicker.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/DateTimePicker.svg
new file mode 100644
index 00000000..278a9a38
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/DateTimePicker.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Expander.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Expander.svg
new file mode 100644
index 00000000..bfe5f6f0
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Expander.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Flame.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Flame.svg
new file mode 100644
index 00000000..aec05ea9
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Flame.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Gift.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Gift.svg
new file mode 100644
index 00000000..df0668b0
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Gift.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Grid.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Grid.svg
new file mode 100644
index 00000000..4722a45d
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Grid.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/GridSplitter.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/GridSplitter.svg
new file mode 100644
index 00000000..b43bf447
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/GridSplitter.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/GroupBox.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/GroupBox.svg
new file mode 100644
index 00000000..bcf0f690
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/GroupBox.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Hand.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Hand.svg
new file mode 100644
index 00000000..2b33eb8f
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Hand.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Hourglass.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Hourglass.svg
new file mode 100644
index 00000000..4c7329c3
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Hourglass.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Image.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Image.svg
new file mode 100644
index 00000000..8be92355
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Image.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/ListBox.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/ListBox.svg
new file mode 100644
index 00000000..c0e2cef2
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/ListBox.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/ListView.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/ListView.svg
new file mode 100644
index 00000000..0b94012f
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/ListView.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Lock.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Lock.svg
new file mode 100644
index 00000000..1701d422
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Lock.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Map.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Map.svg
new file mode 100644
index 00000000..e2415b31
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Map.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Music.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Music.svg
new file mode 100644
index 00000000..dc2781d3
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Music.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/NavMenu3D.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/NavMenu3D.svg
new file mode 100644
index 00000000..1ae039e4
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/NavMenu3D.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Navigation.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Navigation.svg
new file mode 100644
index 00000000..addf8f61
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Navigation.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Network.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Network.svg
new file mode 100644
index 00000000..9725c5d0
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Network.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Palette.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Palette.svg
new file mode 100644
index 00000000..68684d84
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Palette.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Pen.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Pen.svg
new file mode 100644
index 00000000..ba36f7b9
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Pen.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Progress.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Progress.svg
new file mode 100644
index 00000000..99cdba06
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Progress.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/RadioButton.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/RadioButton.svg
new file mode 100644
index 00000000..b454fa3f
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/RadioButton.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Rainbow.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Rainbow.svg
new file mode 100644
index 00000000..7a8b9b62
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Rainbow.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Rocket.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Rocket.svg
new file mode 100644
index 00000000..9f64d22c
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Rocket.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Ruler.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Ruler.svg
new file mode 100644
index 00000000..cd33d23c
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Ruler.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Scroll.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Scroll.svg
new file mode 100644
index 00000000..ceaef8c5
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Scroll.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Search.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Search.svg
new file mode 100644
index 00000000..0b07e622
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Search.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Selection.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Selection.svg
new file mode 100644
index 00000000..838f1b11
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Selection.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Shield.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Shield.svg
new file mode 100644
index 00000000..883a4fb4
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Shield.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Slider.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Slider.svg
new file mode 100644
index 00000000..d655a8d4
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Slider.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Snow.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Snow.svg
new file mode 100644
index 00000000..1bf4d68d
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Snow.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Sparkle.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Sparkle.svg
new file mode 100644
index 00000000..221f433b
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Sparkle.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Spinner.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Spinner.svg
new file mode 100644
index 00000000..5a96004b
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Spinner.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Stars.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Stars.svg
new file mode 100644
index 00000000..c50f6504
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Stars.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Steps.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Steps.svg
new file mode 100644
index 00000000..027d654e
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Steps.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/TabControl.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/TabControl.svg
new file mode 100644
index 00000000..698ad86d
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/TabControl.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Tag.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Tag.svg
new file mode 100644
index 00000000..70a604a0
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Tag.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/TaskbarInfo.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/TaskbarInfo.svg
new file mode 100644
index 00000000..0546c404
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/TaskbarInfo.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Text.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Text.svg
new file mode 100644
index 00000000..88ca5dd3
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Text.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Thermometer.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Thermometer.svg
new file mode 100644
index 00000000..259f7ac0
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Thermometer.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/ToggleButton.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/ToggleButton.svg
new file mode 100644
index 00000000..07c9a87e
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/ToggleButton.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/TreeView.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/TreeView.svg
new file mode 100644
index 00000000..60e4bbcf
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/TreeView.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Vector.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Vector.svg
new file mode 100644
index 00000000..b4ce99f2
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Vector.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Window.svg b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Window.svg
new file mode 100644
index 00000000..d0aaed85
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/Resources/MenuIcons/Window.svg
@@ -0,0 +1 @@
+
diff --git a/src/WPFDevelopers.Samples.Shared/ViewModels/MainVM.cs b/src/WPFDevelopers.Samples.Shared/ViewModels/MainVM.cs
index 812b87d2..d182cda0 100644
--- a/src/WPFDevelopers.Samples.Shared/ViewModels/MainVM.cs
+++ b/src/WPFDevelopers.Samples.Shared/ViewModels/MainVM.cs
@@ -2,9 +2,12 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.ComponentModel;
+using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Input;
+using WPFDevelopers;
using WPFDevelopers.Helpers;
using WPFDevelopers.Sample.ExampleViews;
using WPFDevelopers.Samples.ExampleViews;
@@ -39,6 +42,7 @@ public class MainVM : ViewModelBase
nameof(MenuEnum.DateTimePicker),
nameof(MenuEnum.Calendar),
nameof(MenuEnum.Slider),
+ nameof(MenuEnum.GridSplitter),
nameof(MenuEnum.ProgressBar),
nameof(MenuEnum.DataGrid),
nameof(MenuEnum.ListBox),
@@ -50,6 +54,67 @@ public class MainVM : ViewModelBase
nameof(MenuEnum.TaskbarInfo),
};
+ private static readonly HashSet DemoMenuItems = new HashSet
+ {
+ MenuEnum.StreamerLoading,
+ MenuEnum.TransformLayout,
+ MenuEnum.ChatEmoji,
+ MenuEnum.Dashboard,
+ MenuEnum.PieSegment,
+ MenuEnum.Password,
+ MenuEnum.SongWords,
+ MenuEnum.ActivityFeed,
+ MenuEnum.Flame,
+ MenuEnum.TransitionPanel,
+ MenuEnum.ZooSemy,
+ MenuEnum.RainbowBtn,
+ MenuEnum.RoundPicker,
+ MenuEnum.LineChart,
+ MenuEnum.SnowCanvas,
+ MenuEnum.LoginWindow,
+ MenuEnum.Drawing,
+ MenuEnum.SpeedRockets,
+ MenuEnum.CountdownTimer,
+ MenuEnum.NumberCard,
+ MenuEnum.ImageCrop,
+ MenuEnum.Desktop,
+ MenuEnum.DrawPrize,
+ MenuEnum.BubbleSelection,
+ MenuEnum.CanvasHandWriting,
+ MenuEnum.Barrage,
+ MenuEnum.SixGridView,
+ MenuEnum.Drap,
+ MenuEnum.TaskbarInfo,
+ };
+
+ private static readonly HashSet NewMenuItems = new HashSet
+ {
+ MenuEnum.ScrollNavigation,
+ MenuEnum.Timeline,
+ MenuEnum.Carousel,
+ MenuEnum.CardCarousel,
+ MenuEnum.FocusCarousel
+ };
+
+ private static readonly HashSet UpdatedMenuItems = new HashSet
+ {
+ MenuEnum.ComboBox,
+ MenuEnum.DatePicker,
+ MenuEnum.DateTimePicker,
+ MenuEnum.DataGrid,
+ MenuEnum.ListBox,
+ MenuEnum.ListView,
+ MenuEnum.Window,
+ MenuEnum.GridSplitter,
+ MenuEnum.ScrollViewer,
+ MenuEnum.ScreenCut,
+ MenuEnum.ColorPicker,
+ MenuEnum.TimePicker,
+ MenuEnum.DateRangePicker,
+ MenuEnum.VirtualizingWrapPanel,
+ MenuEnum.WaterfallPanel,
+ };
+
private IList _navigateMenuModelList;
public IList NavigateMenuModelList
@@ -76,11 +141,67 @@ public NavigateMenuModel NavigateMenuItem
}
}
private object _controlPanel;
+ private HomeExample _homePage;
private ObservableCollection _customMenuModelList;
private ObservableCollection _basicMenuModelList;
private int _segmentedSelectedIndex;
private string _searchText = string.Empty;
+ private string _searchWatermark;
+ private string _customMenuLabel;
+ private string _basicMenuLabel;
+ private string _demoBadgeToolTip;
+
+ public bool IsChineseLanguage
+ {
+ get { return LanguageManager.Instance.CurrentCulture.TwoLetterISOLanguageName == "zh"; }
+ set
+ {
+ var cultureName = value ? "zh-CN" : "en-US";
+ if (LanguageManager.Instance.CurrentCulture.Name != cultureName)
+ LanguageManager.Instance.ChangeLanguage(new CultureInfo(cultureName));
+ }
+ }
+
+ public string SearchWatermark
+ {
+ get { return _searchWatermark; }
+ private set
+ {
+ _searchWatermark = value;
+ NotifyPropertyChange(nameof(SearchWatermark));
+ }
+ }
+
+ public string CustomMenuLabel
+ {
+ get { return _customMenuLabel; }
+ private set
+ {
+ _customMenuLabel = value;
+ NotifyPropertyChange(nameof(CustomMenuLabel));
+ }
+ }
+
+ public string BasicMenuLabel
+ {
+ get { return _basicMenuLabel; }
+ private set
+ {
+ _basicMenuLabel = value;
+ NotifyPropertyChange(nameof(BasicMenuLabel));
+ }
+ }
+
+ public string DemoBadgeToolTip
+ {
+ get { return _demoBadgeToolTip; }
+ private set
+ {
+ _demoBadgeToolTip = value;
+ NotifyPropertyChange(nameof(DemoBadgeToolTip));
+ }
+ }
public int SegmentedSelectedIndex
{
@@ -115,23 +236,346 @@ public MainVM()
foreach (MenuEnum menuEnum in Enum.GetValues(typeof(MenuEnum)))
{
var name = menuEnum.ToString();
+ var menuModel = new NavigateMenuModel
+ {
+ Name = name,
+ IsDemo = DemoMenuItems.Contains(menuEnum),
+ IconSource = GetMenuIconSource(menuEnum)
+ };
+ if (NewMenuItems.Contains(menuEnum))
+ menuModel.ChangeType = "New";
+ else if (UpdatedMenuItems.Contains(menuEnum))
+ menuModel.ChangeType = "Updated";
+
if (BasicEnumSet.Contains(name))
- _basicMenuModelList.Add(new NavigateMenuModel { Name = name });
+ _basicMenuModelList.Add(menuModel);
else
- _customMenuModelList.Add(new NavigateMenuModel { Name = name });
+ _customMenuModelList.Add(menuModel);
}
NavigateMenuModelList = _customMenuModelList;
_navigateMenuItem = NavigateMenuModelList.First();
- _customMenuModelList.Add(new NavigateMenuModel { Name = "持续更新中" });
- ControlPanel = new NavMenu3DExample();
+ _customMenuModelList.Add(new NavigateMenuModel
+ {
+ Name = "持续更新中",
+ IconSource = GetMenuIconSource("Navigation")
+ });
+ LanguageManager.Instance.PropertyChanged += LanguageManager_PropertyChanged;
+ UpdateMenuDisplayNames();
+ ShowHome();
}
- public ICommand ViewLoaded => new RelayCommand(obj =>
+ private static string GetMenuIconSource(MenuEnum menuEnum)
{
+ string iconName;
+ switch (menuEnum)
+ {
+ case MenuEnum.NavMenu3D:
+ iconName = "NavMenu3D";
+ break;
+ case MenuEnum.MapView:
+ iconName = "Map";
+ break;
+ case MenuEnum.UsageGuide:
+ case MenuEnum.MarkdownViewer:
+ iconName = "Book";
+ break;
+ case MenuEnum.UsageColor:
+ case MenuEnum.ColorPicker:
+ case MenuEnum.Theme:
+ iconName = "Palette";
+ break;
+ case MenuEnum.MessageBox:
+ case MenuEnum.Toast:
+ case MenuEnum.ChatEmoji:
+ case MenuEnum.Barrage:
+ iconName = "Chat";
+ break;
+ case MenuEnum.NotifyIcon:
+ case MenuEnum.Badge:
+ iconName = "Activity";
+ break;
+ case MenuEnum.PanningItems:
+ case MenuEnum.Drap:
+ iconName = "Hand";
+ break;
+ case MenuEnum.BreatheLight:
+ case MenuEnum.SpotLight:
+ case MenuEnum.EdgeLight:
+ case MenuEnum.AcrylicBlur:
+ iconName = "Sparkle";
+ break;
+ case MenuEnum.RingLoading:
+ case MenuEnum.Loading:
+ case MenuEnum.BasicLoading:
+ case MenuEnum.CircleProgressBar:
+ iconName = "Spinner";
+ break;
+ case MenuEnum.ProgressBar:
+ iconName = "Progress";
+ break;
+ case MenuEnum.BallLoading:
+ case MenuEnum.RoundPicker:
+ case MenuEnum.Gauge:
+ case MenuEnum.Dial:
+ iconName = "Circle";
+ break;
+ case MenuEnum.StreamerLoading:
+ case MenuEnum.WaitLoading:
+ case MenuEnum.CycleLoading:
+ case MenuEnum.RollLoading:
+ iconName = "Hourglass";
+ break;
+ case MenuEnum.CropAvatar:
+ case MenuEnum.CropImage:
+ case MenuEnum.ImageCrop:
+ case MenuEnum.ScreenCut:
+ iconName = "Crop";
+ break;
+ case MenuEnum.AnimationAudio:
+ case MenuEnum.SongWords:
+ iconName = "Music";
+ break;
+ case MenuEnum.TransformLayout:
+ case MenuEnum.WaterfallPanel:
+ case MenuEnum.VirtualizingWrapPanel:
+ case MenuEnum.SixGridView:
+ iconName = "Grid";
+ break;
+ case MenuEnum.GridSplitter:
+ iconName = "GridSplitter";
+ break;
+ case MenuEnum.VerifyCode:
+ case MenuEnum.OtpBox:
+ case MenuEnum.GestureUnlock:
+ iconName = "Shield";
+ break;
+ case MenuEnum.CircleMenu:
+ case MenuEnum.DrawerMenu:
+ case MenuEnum.Drawer:
+ case MenuEnum.Menu:
+ case MenuEnum.NavScrollPanel:
+ case MenuEnum.ScrollNavigation:
+ iconName = "Navigation";
+ break;
+ case MenuEnum.Dashboard:
+ case MenuEnum.NumberCard:
+ case MenuEnum.DataGridFilter:
+ iconName = "Dashboard";
+ break;
+ case MenuEnum.DataGrid:
+ iconName = "DataGrid";
+ break;
+ case MenuEnum.PieSegment:
+ case MenuEnum.ChartPie:
+ case MenuEnum.ChartRadar:
+ case MenuEnum.ChartBar:
+ case MenuEnum.ChartLine:
+ case MenuEnum.LineChart:
+ iconName = "Chart";
+ break;
+ case MenuEnum.Password:
+ case MenuEnum.PasswordBox:
+ iconName = "Lock";
+ break;
+ case MenuEnum.ActivityFeed:
+ case MenuEnum.Timeline:
+ iconName = "Activity";
+ break;
+ case MenuEnum.CardCarousel:
+ case MenuEnum.FocusCarousel:
+ case MenuEnum.Carousel:
+ case MenuEnum.Pagination:
+ iconName = "Cards";
+ break;
+ case MenuEnum.ScrollViewer:
+ iconName = "Scroll";
+ break;
+ case MenuEnum.Flame:
+ iconName = "Flame";
+ break;
+ case MenuEnum.ZooSemy:
+ iconName = "Animal";
+ break;
+ case MenuEnum.Ruler:
+ case MenuEnum.Spacing:
+ iconName = "Ruler";
+ break;
+ case MenuEnum.RainbowBtn:
+ iconName = "Rainbow";
+ break;
+ case MenuEnum.Thermometer:
+ iconName = "Thermometer";
+ break;
+ case MenuEnum.SnowCanvas:
+ iconName = "Snow";
+ break;
+ case MenuEnum.LoginWindow:
+ case MenuEnum.Desktop:
+ case MenuEnum.Window:
+ iconName = "Window";
+ break;
+ case MenuEnum.Drawing:
+ case MenuEnum.CanvasHandWriting:
+ iconName = "Pen";
+ break;
+ case MenuEnum.SpeedRockets:
+ iconName = "Rocket";
+ break;
+ case MenuEnum.CountdownTimer:
+ case MenuEnum.DateRangePicker:
+ case MenuEnum.Calendar:
+ iconName = "Calendar";
+ break;
+ case MenuEnum.TimePicker:
+ case MenuEnum.DateTimePicker:
+ iconName = "DateTimePicker";
+ break;
+ case MenuEnum.DatePicker:
+ iconName = "DatePicker";
+ break;
+ case MenuEnum.DrawPrize:
+ iconName = "Gift";
+ break;
+ case MenuEnum.StarrySky:
+ iconName = "Stars";
+ break;
+ case MenuEnum.Shake:
+ case MenuEnum.TransitionPanel:
+ case MenuEnum.AnimationGrid:
+ iconName = "Activity";
+ break;
+ case MenuEnum.BubbleSelection:
+ iconName = "Circle";
+ break;
+ case MenuEnum.Magnifier:
+ iconName = "Search";
+ break;
+ case MenuEnum.Step:
+ iconName = "Steps";
+ break;
+ case MenuEnum.MultiSelectComboBox:
+ case MenuEnum.Selector:
+ case MenuEnum.Segmented:
+ case MenuEnum.SplitButton:
+ iconName = "Selection";
+ break;
+ case MenuEnum.ToggleButton:
+ iconName = "ToggleButton";
+ break;
+ case MenuEnum.RadioButton:
+ iconName = "RadioButton";
+ break;
+ case MenuEnum.Checkbox:
+ iconName = "Checkbox";
+ break;
+ case MenuEnum.Mask:
+ case MenuEnum.GrayscaleEffect:
+ iconName = "Image";
+ break;
+ case MenuEnum.BreadCrumbBar:
+ iconName = "Navigation";
+ break;
+ case MenuEnum.PathIcon:
+ case MenuEnum.AllPathIcon:
+ case MenuEnum.SvgViewer:
+ iconName = "Vector";
+ break;
+ case MenuEnum.NumericBox:
+ case MenuEnum.TextBox:
+ iconName = "Text";
+ break;
+ case MenuEnum.IPEditBox:
+ iconName = "Network";
+ break;
+ case MenuEnum.Tag:
+ iconName = "Tag";
+ break;
+ case MenuEnum.IconicThumbnail:
+ iconName = "Image";
+ break;
+ case MenuEnum.Slider:
+ iconName = "Slider";
+ break;
+ case MenuEnum.Button:
+ iconName = "Button";
+ break;
+ case MenuEnum.ComboBox:
+ iconName = "ComboBox";
+ break;
+ case MenuEnum.ListBox:
+ iconName = "ListBox";
+ break;
+ case MenuEnum.ListView:
+ iconName = "ListView";
+ break;
+ case MenuEnum.TreeView:
+ iconName = "TreeView";
+ break;
+ case MenuEnum.GroupBox:
+ iconName = "GroupBox";
+ break;
+ case MenuEnum.TabControl:
+ iconName = "TabControl";
+ break;
+ case MenuEnum.Expander:
+ iconName = "Expander";
+ break;
+ case MenuEnum.TaskbarInfo:
+ iconName = "TaskbarInfo";
+ break;
+ default:
+ iconName = "Navigation";
+ break;
+ }
+
+ return GetMenuIconSource(iconName);
+ }
+
+ private static string GetMenuIconSource(string iconName)
+ {
+ return "pack://application:,,,/WPFDevelopers.Samples;component/Resources/MenuIcons/"
+ + iconName + ".svg";
+ }
+ private void LanguageManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
+ {
+ if (e.PropertyName == nameof(LanguageManager.CurrentCulture))
+ UpdateMenuDisplayNames();
+ }
+
+ private void UpdateMenuDisplayNames()
+ {
+ var culture = LanguageManager.Instance.CurrentCulture;
+ var isChinese = culture.TwoLetterISOLanguageName == "zh";
+ NotifyPropertyChange(nameof(IsChineseLanguage));
+ SearchWatermark = isChinese ? "搜索控件" : "Search Control";
+ CustomMenuLabel = isChinese ? "自定义" : "Custom";
+ BasicMenuLabel = isChinese ? "基础控件" : "Basic";
+ DemoBadgeToolTip = isChinese
+ ? "示例专属实现或组合效果,非 WD 内置控件;请参考示例源码。"
+ : "Sample-only implementation or composition, not a built-in WD control. See the sample source.";
+ foreach (var item in _customMenuModelList.Concat(_basicMenuModelList))
+ item.DisplayName = MenuNameLocalizer.GetDisplayName(item.Name, culture);
+
+ ApplySearchFilter();
+ }
+
+ 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 =>
{
_searchText = obj.ToString();
@@ -149,7 +593,8 @@ private void ApplySearchFilter()
var key = _searchText.ToLower();
foreach (var item in NavigateMenuModelList)
{
- item.IsVisible = item.Name.ToLower().Contains(key);
+ item.IsVisible = item.Name.ToLower().Contains(key) ||
+ item.DisplayName.ToLower().Contains(key);
}
}
}
@@ -230,6 +675,9 @@ void MenuItemSelection(string _menuName)
case MenuEnum.Slider:
ControlPanel = new SliderExample();
break;
+ case MenuEnum.GridSplitter:
+ ControlPanel = new GridSplitterExample();
+ break;
case MenuEnum.ProgressBar:
ControlPanel = new ProgressBarExample();
break;
@@ -310,8 +758,8 @@ void MenuItemSelection(string _menuName)
case MenuEnum.Dashboard:
ControlPanel = new DashboardExample();
break;
- case MenuEnum.PieControl:
- ControlPanel = new PieControlExample();
+ case MenuEnum.PieSegment:
+ ControlPanel = new PieSegmentExample();
break;
case MenuEnum.Password:
ControlPanel = new PasswordExample();
@@ -319,20 +767,23 @@ void MenuItemSelection(string _menuName)
case MenuEnum.SongWords:
ControlPanel = new SongWordsExample();
break;
- case MenuEnum.TimeLine:
- ControlPanel = new TimeLineExample();
+ case MenuEnum.ActivityFeed:
+ ControlPanel = new ActivityFeedExample();
break;
case MenuEnum.ScrollViewer:
ControlPanel = new ScrollViewerAnimationExample();
break;
+ case MenuEnum.ScrollNavigation:
+ ControlPanel = new ScrollNavigationExample();
+ break;
case MenuEnum.CardCarousel:
ControlPanel = new CardCarouselExample();
break;
case MenuEnum.FocusCarousel:
ControlPanel = new FocusCarouselExample();
break;
- case MenuEnum.OtherControls:
- ControlPanel = new OtherControlExample();
+ case MenuEnum.Flame:
+ ControlPanel = new FlameExample();
break;
case MenuEnum.ScreenCut:
ControlPanel = new ScreenCutExample();
@@ -363,8 +814,8 @@ void MenuItemSelection(string _menuName)
case MenuEnum.ZooSemy:
ControlPanel = new ZooSemyExample();
break;
- case MenuEnum.RulerControl:
- ControlPanel = new RulerControlExample();
+ case MenuEnum.Ruler:
+ ControlPanel = new RulerExample();
break;
case MenuEnum.RainbowBtn:
ControlPanel = new RainbowButtonsExample();
@@ -396,8 +847,8 @@ void MenuItemSelection(string _menuName)
case MenuEnum.NumberCard:
ControlPanel = new NumberCardExample();
break;
- case MenuEnum.CropControl:
- ControlPanel = new CropControlExample();
+ case MenuEnum.ImageCrop:
+ ControlPanel = new ImageCropExample();
break;
case MenuEnum.Desktop:
ControlPanel = new DesktopBackground();
@@ -417,8 +868,8 @@ void MenuItemSelection(string _menuName)
case MenuEnum.PanningItems:
ControlPanel = new PanningItemsExample();
break;
- case MenuEnum.BubblleControl:
- ControlPanel = new BubblleControlExample();
+ case MenuEnum.BubbleSelection:
+ ControlPanel = new BubbleSelectionExample();
break;
case MenuEnum.CanvasHandWriting:
ControlPanel = new CanvasHandWritingExample();
@@ -447,9 +898,9 @@ void MenuItemSelection(string _menuName)
case MenuEnum.Selector:
ControlPanel = new SelectorExample();
break;
- case MenuEnum.MultiSelectSearchComboBox:
- ControlPanel = new MultiSelectSearchComboBoxExample();
- break;
+ //case MenuEnum.MultiSelectSearchComboBox:
+ // ControlPanel = new MultiSelectSearchComboBoxExample();
+ // break;
case MenuEnum.BreadCrumbBar:
ControlPanel = new BreadCrumbBarExample();
break;
@@ -550,6 +1001,9 @@ void MenuItemSelection(string _menuName)
case MenuEnum.MapView:
ControlPanel = new MapViewExample();
break;
+ case MenuEnum.Timeline:
+ ControlPanel = new TimelineExample();
+ break;
//新的添加到上方
case MenuEnum.VirtualizingWrapPanel:
ControlPanel = new VirtualizingWrapPanel();
diff --git a/src/WPFDevelopers.Samples.Shared/ViewModels/TimelineExampleVM.cs b/src/WPFDevelopers.Samples.Shared/ViewModels/TimelineExampleVM.cs
new file mode 100644
index 00000000..0d12bd43
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/ViewModels/TimelineExampleVM.cs
@@ -0,0 +1,150 @@
+using System;
+using System.Collections.ObjectModel;
+using System.Windows.Controls;
+using System.Windows.Input;
+using System.Windows.Media;
+using WPFDevelopers.Controls;
+using WPFDevelopers.Samples.Helpers;
+
+namespace WPFDevelopers.Samples.ViewModels
+{
+ public class TimelineExampleVM : ViewModelBase
+ {
+ private Orientation _orientation = Orientation.Vertical;
+ private TimelineMode _mode = TimelineMode.Alternate;
+ private bool _reverse;
+ private int _eventNumber;
+
+ public ObservableCollection Events { get; private set; }
+ public Array Orientations { get; private set; }
+ public Array Modes { get; private set; }
+ public ICommand AddCommand { get; private set; }
+ public ICommand RemoveCommand { get; private set; }
+ public ICommand ResetCommand { get; private set; }
+ public ICommand CompleteCommand { get; private set; }
+ public ICommand NextCommand { get; private set; }
+
+ public Orientation Orientation
+ {
+ get { return _orientation; }
+ set { _orientation = value; NotifyPropertyChange(nameof(Orientation)); }
+ }
+
+ public TimelineMode Mode
+ {
+ get { return _mode; }
+ set { _mode = value; NotifyPropertyChange(nameof(Mode)); }
+ }
+
+ public bool Reverse
+ {
+ get { return _reverse; }
+ set { _reverse = value; NotifyPropertyChange(nameof(Reverse)); }
+ }
+
+ public TimelineExampleVM()
+ {
+ Events = new ObservableCollection();
+ Orientations = Enum.GetValues(typeof(Orientation));
+ Modes = Enum.GetValues(typeof(TimelineMode));
+ AddCommand = new RelayCommand(_ => AddEvent());
+ RemoveCommand = new RelayCommand(_ =>
+ {
+ if (Events.Count > 0) Events.RemoveAt(Events.Count - 1);
+ });
+ ResetCommand = new RelayCommand(_ => ResetEvents());
+ CompleteCommand = new RelayCommand(_ => CompleteEvents(true));
+ NextCommand = new RelayCommand(_ =>
+ {
+ CompleteEvents(false);
+ AddEvent(true);
+ });
+ ResetEvents();
+ }
+
+ private void CompleteEvents(bool onlyLoading)
+ {
+ foreach (var item in Events)
+ {
+ if (onlyLoading && !item.IsLoading) continue;
+ item.IsLoading = false;
+ item.Title = "Completed";
+ item.Description = "Updated through INotifyPropertyChanged.";
+ item.Brush = Brushes.SeaGreen;
+ }
+ }
+
+ private void AddEvent(bool isLoading = false)
+ {
+ Events.Add(new TimelineEvent
+ {
+ Time = DateTime.Now.ToString("HH:mm:ss"),
+ Title = "Event " + ++_eventNumber,
+ Description = "Added by a ViewModel command.",
+ Brush = Brushes.DodgerBlue,
+ IsLoading = isLoading
+ });
+ }
+
+ private void ResetEvents()
+ {
+ Events.Clear();
+ _eventNumber = 3;
+ Events.Add(new TimelineEvent
+ {
+ Time = "09:00", Title = "Created",
+ Description = "Create a service site.", Brush = Brushes.DodgerBlue
+ });
+ Events.Add(new TimelineEvent
+ {
+ Time = "10:00", Title = "Completed",
+ Description = "Solve initial network problems.", Brush = Brushes.SeaGreen
+ });
+ Events.Add(new TimelineEvent
+ {
+ Time = "11:00", Title = "In progress",
+ Description = "Technical testing is in progress.", Brush = Brushes.DodgerBlue,
+ IsLoading = true
+ });
+ }
+ }
+
+ public class TimelineEvent : ViewModelBase
+ {
+ private string _time;
+ private string _title;
+ private string _description;
+ private Brush _brush;
+ private bool _isLoading;
+
+ public string Time
+ {
+ get { return _time; }
+ set { _time = value; NotifyPropertyChange(nameof(Time)); }
+ }
+
+ public string Title
+ {
+ get { return _title; }
+ set { _title = value; NotifyPropertyChange(nameof(Title)); }
+ }
+
+ public string Description
+ {
+ get { return _description; }
+ set { _description = value; NotifyPropertyChange(nameof(Description)); }
+ }
+
+ public Brush Brush
+ {
+ get { return _brush; }
+ set { _brush = value; NotifyPropertyChange(nameof(Brush)); }
+ }
+
+ public bool IsLoading
+ {
+ get { return _isLoading; }
+ set { _isLoading = value; NotifyPropertyChange(nameof(IsLoading)); }
+ }
+ }
+}
diff --git a/src/WPFDevelopers.Samples.Shared/ViewModels/WaterfallPanelExampleVM.cs b/src/WPFDevelopers.Samples.Shared/ViewModels/WaterfallPanelExampleVM.cs
new file mode 100644
index 00000000..c00e522d
--- /dev/null
+++ b/src/WPFDevelopers.Samples.Shared/ViewModels/WaterfallPanelExampleVM.cs
@@ -0,0 +1,60 @@
+using System;
+using System.Collections.ObjectModel;
+
+namespace WPFDevelopers.Samples.ViewModels
+{
+ public class WaterfallPanelExampleVM : ViewModelBase
+ {
+ public ObservableCollection Items { get; private set; }
+ public ObservableCollection LargeItems { get; private set; }
+
+ public WaterfallPanelExampleVM()
+ {
+ Items = new ObservableCollection
+ {
+ new WaterfallPanelItem("https://images.unsplash.com/photo-1510001618818-4b4e3d86bf0f?w=523&auto=format"),
+ new WaterfallPanelItem("https://images.unsplash.com/photo-1507513319174-e556268bb244?w=523&auto=format"),
+ new WaterfallPanelItem("https://images.unsplash.com/photo-1474181487882-5abf3f0ba6c2?w=523&auto=format"),
+ new WaterfallPanelItem("https://images.unsplash.com/photo-1492778297155-7be4c83960c7?w=523&auto=format"),
+ new WaterfallPanelItem("https://images.unsplash.com/photo-1508062878650-88b52897f298?w=523&auto=format"),
+ new WaterfallPanelItem("https://images.unsplash.com/photo-1506158278516-d720e72406fc?w=523&auto=format"),
+ new WaterfallPanelItem("https://images.unsplash.com/photo-1552203274-e3c7bd771d26?w=523&auto=format"),
+ new WaterfallPanelItem("https://images.unsplash.com/photo-1528163186890-de9b86b54b51?w=523&auto=format"),
+ new WaterfallPanelItem("https://images.unsplash.com/photo-1727423304224-6d2fd99b864c?w=523&auto=format"),
+ new WaterfallPanelItem("https://images.unsplash.com/photo-1675090391405-432434e23595?w=523&auto=format"),
+ new WaterfallPanelItem("https://images.unsplash.com/photo-1554196967-97a8602084d9?w=523&auto=format"),
+ new WaterfallPanelItem("https://images.unsplash.com/photo-1491961865842-98f7befd1a60?w=523&auto=format"),
+ new WaterfallPanelItem("https://images.unsplash.com/photo-1721728613411-d56d2ddda959?w=523&auto=format"),
+ new WaterfallPanelItem("https://images.unsplash.com/photo-1731901245099-20ac7f85dbaa?w=523&auto=format"),
+ new WaterfallPanelItem("https://images.unsplash.com/photo-1617694455303-59af55af7e58?w=523&auto=format"),
+ new WaterfallPanelItem("https://images.unsplash.com/photo-1709198165282-1dab551df890?w=523&auto=format")
+ };
+
+ LargeItems = new ObservableCollection();
+ for (var index = 0; index < 5000; index++)
+ {
+ LargeItems.Add(new WaterfallDemoItem
+ {
+ Title = "Item " + (index + 1),
+ Height = 100 + (index * 37 % 220)
+ });
+ }
+ }
+ }
+
+ public class WaterfallDemoItem
+ {
+ public string Title { get; set; }
+ public double Height { get; set; }
+ }
+
+ public class WaterfallPanelItem
+ {
+ public Uri ImageUri { get; private set; }
+
+ public WaterfallPanelItem(string imageUrl)
+ {
+ ImageUri = new Uri(imageUrl, UriKind.Absolute);
+ }
+ }
+}
diff --git a/src/WPFDevelopers.Samples.Shared/WPFDevelopers.Samples.Shared.projitems b/src/WPFDevelopers.Samples.Shared/WPFDevelopers.Samples.Shared.projitems
index aff8e4a1..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 @@
-
-
-
+
+
+
@@ -49,8 +63,8 @@
-
-
+
+
@@ -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
@@ -527,9 +545,13 @@
Code
TransformLayoutExample.xaml
-
+
Code
- TimeLineExample.xaml
+ ActivityFeedExample.xaml
+
+
+ Code
+ TimelineExample.xaml
Code
@@ -612,6 +634,9 @@
SliderExample.xaml
+
+ GridSplitterExample.xaml
+
ProgressBarExample.xaml
@@ -638,6 +663,7 @@
+
@@ -647,10 +673,12 @@
+
+
-
+
MSBuild:Compile
Designer
@@ -662,7 +690,7 @@
MSBuild:Compile
Designer
-
+
MSBuild:Compile
Designer
@@ -698,11 +726,11 @@
MSBuild:Compile
Designer
-
+
MSBuild:Compile
Designer
-
+
MSBuild:Compile
Designer
@@ -722,7 +750,7 @@
MSBuild:Compile
Designer
-
+
MSBuild:Compile
Designer
@@ -794,7 +822,7 @@
MSBuild:Compile
Designer
-
+
MSBuild:Compile
Designer
@@ -850,7 +878,7 @@
MSBuild:Compile
Designer
-
+
MSBuild:Compile
Designer
@@ -1123,7 +1151,7 @@
MSBuild:Compile
Designer
-
+
MSBuild:Compile
Designer
@@ -1147,7 +1175,7 @@
MSBuild:Compile
Designer
-
+
MSBuild:Compile
Designer
@@ -1163,7 +1191,7 @@
MSBuild:Compile
Designer
-
+
MSBuild:Compile
Designer
@@ -1175,6 +1203,10 @@
MSBuild:Compile
Designer
+
+ MSBuild:Compile
+ Designer
+
MSBuild:Compile
Designer
@@ -1243,7 +1275,11 @@
MSBuild:Compile
Designer
-
+
+ MSBuild:Compile
+ Designer
+
+
MSBuild:Compile
Designer
@@ -1343,6 +1379,10 @@
MSBuild:Compile
Designer
+
+ MSBuild:Compile
+ Designer
+
MSBuild:Compile
Designer
@@ -1386,4 +1426,4 @@
-
+
\ No newline at end of file
diff --git a/src/WPFDevelopers.Samples.Shared/app.manifest b/src/WPFDevelopers.Samples.Shared/app.manifest
index 3694c535..02624d55 100644
--- a/src/WPFDevelopers.Samples.Shared/app.manifest
+++ b/src/WPFDevelopers.Samples.Shared/app.manifest
@@ -1,6 +1,5 @@
-
diff --git a/src/WPFDevelopers.SamplesCode/WPFDevelopers.SamplesCode.csproj b/src/WPFDevelopers.SamplesCode/WPFDevelopers.SamplesCode.csproj
index eccd6eec..18af66d1 100644
--- a/src/WPFDevelopers.SamplesCode/WPFDevelopers.SamplesCode.csproj
+++ b/src/WPFDevelopers.SamplesCode/WPFDevelopers.SamplesCode.csproj
@@ -17,6 +17,8 @@
+
+
@@ -25,7 +27,7 @@
-
+
@@ -38,7 +40,7 @@
-
+
@@ -70,20 +72,21 @@
-
+
-
+
-
+
+
@@ -93,13 +96,17 @@
-
+
+
+
+
+
@@ -113,11 +120,11 @@
-
-
+
+
-
+
@@ -125,8 +132,8 @@
-
-
+
+
@@ -140,7 +147,7 @@
-
+
@@ -166,8 +173,8 @@
-
-
+
+
@@ -236,8 +243,8 @@
ExampleViews\BreatheLightExample.xaml
-
- ExampleViews\BubblleControlExample.xaml
+
+ ExampleViews\BubbleSelectionExample.xaml
ExampleViews\CanvasHandWriting\CanvasHandWritingExample.xaml
@@ -266,8 +273,8 @@
ExampleViews\CropAvatar\CropAvatarWindow.xaml
-
- ExampleViews\CropControlExample.xaml
+
+ ExampleViews\ImageCropExample.xaml
ExampleViews\CutImageExample.xaml
@@ -367,8 +374,8 @@
ExampleViews\NumberCard\NumberCardExample.xaml
-
- ExampleViews\OtherControlExample.xaml
+
+ ExampleViews\FlameExample.xaml
ExampleViews\PaginationExample.xaml
@@ -383,8 +390,8 @@
ExampleViews\Passwrod\PasswordWithPlainText.xaml
-
- ExampleViews\PieControlExample.xaml
+
+ ExampleViews\PieSegmentExample.xaml
ExampleViews\ChartRadarExample.xaml
@@ -395,8 +402,8 @@
ExampleViews\RoundPickerExample.xaml
-
- ExampleViews\RulerControlExample.xaml
+
+ ExampleViews\RulerExample.xaml
ExampleViews\ScreenCutExample.xaml
@@ -404,6 +411,9 @@
ExampleViews\ScrollViewerAnimationExample.xaml
+
+ ExampleViews\ScrollNavigationExample.xaml
+
ExampleViews\ShakeExample.xaml
@@ -435,8 +445,8 @@
ExampleViews\TransformLayoutExample.xaml
-
- ExampleViews\TimeLineExample.xaml
+
+ ExampleViews\ActivityFeedExample.xaml
ExampleViews\TransitionPanelExample.xaml
@@ -482,14 +492,14 @@
ExampleViews\BreadCrumbBarExample.xaml
-
- Controls\TimeLine\TimeLine.xaml
+
+ Controls\ActivityFeed\ActivityFeed.xaml
Controls\Drawing\Drawing.xaml
-
- Controls\Others\OtherControl.xaml
+
+ Controls\Others\Flame.xaml
Controls\TransformLayout\TransformLayout.xaml
@@ -506,8 +516,8 @@
Controls\Dashboard\Dashboard.xaml
-
- Controls\PieControl\PieControl.xaml
+
+ Controls\PieSegment\PieSegment.xaml
Controls\Prize\PrizeItemControl.xaml
@@ -518,8 +528,8 @@
Controls\SnowCanvas\SnowCanvas.xaml
-
- Controls\CropControl\CropControl.xaml
+
+ Controls\ImageCrop\ImageCrop.xaml
ExampleViews\CropImageExample.xaml
@@ -590,8 +600,8 @@
Controls\Theme\Theme.xaml
-
- Controls\BubblleControl\BubblleControl.xaml
+
+ Controls\BubbleSelection\BubbleSelection.xaml
ExampleViews\NavScrollPanelExample.xaml
@@ -680,6 +690,9 @@
ExampleViews\Basics\SliderExample.xaml
+
+ ExampleViews\Basics\GridSplitterExample.xaml
+
ExampleViews\Basics\ProgressBarExample.xaml
diff --git a/src/WPFDevelopers.Shared/Controls/Carousel/FocusCarousel.cs b/src/WPFDevelopers.Shared/Controls/Carousel/FocusCarousel.cs
index 93c9ebd1..9bceca06 100644
--- a/src/WPFDevelopers.Shared/Controls/Carousel/FocusCarousel.cs
+++ b/src/WPFDevelopers.Shared/Controls/Carousel/FocusCarousel.cs
@@ -166,6 +166,7 @@ protected override void OnItemsSourceChangedCore(object oldValue, object newValu
}
private bool _isAnimating;
+ private Storyboard _activeStoryboard;
protected override void OnSelectedIndexChangedCore(int oldIndex, int newIndex)
{
@@ -399,6 +400,19 @@ public bool OnSizeChangedCallback()
private void FocusCarousel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
+ if (_isAnimating)
+ {
+ if (_activeStoryboard != null)
+ {
+ _activeStoryboard.Stop();
+ _activeStoryboard = null;
+ }
+
+ _isAnimating = false;
+ if (_displayItem != null)
+ OnSizeChangedCallback();
+ }
+
if (sender == _displayItem)
return;
@@ -419,7 +433,7 @@ private void FocusCarousel_MouseLeftButtonDown(object sender, MouseButtonEventAr
var vLeft = (_displayWidth - _simpleWidth) / 2d;
var vTop = (_displayHeight - _simpleHeight) / 2d;
- //一系列计算 计算得到当前展示页要回到的Dock位置
+ //一系列计算 计算得到当前展示页要回到的Dock位置
//一系列计算 计算得到当前点击页要移除的Dock位置
var nTargertIndex = nIndex;
@@ -469,7 +483,7 @@ private void FocusCarousel_MouseLeftButtonDown(object sender, MouseButtonEventAr
var point = _mapCanvasPoint.GetValueOrDefault(nTargertIndex);
- //定义动画
+ //定义动画
var storyboard = new Storyboard
{
SpeedRatio = 2
@@ -704,11 +718,13 @@ private void FocusCarousel_MouseLeftButtonDown(object sender, MouseButtonEventAr
ReplaceImageBitmap(vFrameWorker, _displayWidth, _displayHeight);
ReplaceImageBitmap(_displayItem, _simpleWidth, _simpleHeight);
- var oldDisplayItem = _displayItem;
-
+ _activeStoryboard = storyboard;
_isAnimating = true;
storyboard.Completed += (s, _) =>
{
+ if (_activeStoryboard == s)
+ _activeStoryboard = null;
+
_displayItem = vFrameWorker;
_isAnimating = false;
};
@@ -767,4 +783,4 @@ private void FocusCarousel_SizeChanged(object sender, SizeChangedEventArgs e)
OnSizeChangedCallback();
}
}
-}
\ No newline at end of file
+}
diff --git a/src/WPFDevelopers.Shared/Controls/ColorPicker/ColorPicker.Popup.cs b/src/WPFDevelopers.Shared/Controls/ColorPicker/ColorPicker.Popup.cs
new file mode 100644
index 00000000..379c29e6
--- /dev/null
+++ b/src/WPFDevelopers.Shared/Controls/ColorPicker/ColorPicker.Popup.cs
@@ -0,0 +1,243 @@
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Controls.Primitives;
+using System.Windows.Input;
+using System.Windows.Media;
+
+namespace WPFDevelopers.Controls
+{
+ [TemplatePart(Name = PopupTemplateName, Type = typeof(Popup))]
+ [TemplatePart(Name = ColorPickerTemplateName, Type = typeof(ColorPicker))]
+ [TemplatePart(Name = ToggleButtonTemplateName, Type = typeof(ToggleButton))]
+ public partial class ColorPicker
+ {
+ private const string PopupTemplateName = "PART_Popup";
+ private const string ColorPickerTemplateName = "PART_ColorPicker";
+ private const string ToggleButtonTemplateName = "PART_ToggleButton";
+
+ public static readonly DependencyProperty DisplayModeProperty =
+ DependencyProperty.Register("DisplayMode", typeof(ColorPickerDisplayMode), typeof(ColorPicker),
+ new PropertyMetadata(ColorPickerDisplayMode.Inline, OnDisplayModeChanged),
+ value => (ColorPickerDisplayMode)value == ColorPickerDisplayMode.Inline ||
+ (ColorPickerDisplayMode)value == ColorPickerDisplayMode.Popup);
+
+ public static readonly DependencyProperty IsDropDownOpenProperty =
+ DependencyProperty.Register("IsDropDownOpen", typeof(bool), typeof(ColorPicker),
+ new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
+ null, CoerceIsDropDownOpen));
+
+ public static readonly DependencyProperty ShowColorTextProperty =
+ DependencyProperty.Register("ShowColorText", typeof(bool), typeof(ColorPicker),
+ new PropertyMetadata(false));
+
+ public static readonly DependencyProperty SwatchSizeProperty =
+ DependencyProperty.Register("SwatchSize", typeof(double), typeof(ColorPicker),
+ new PropertyMetadata(18.0), value =>
+ {
+ var size = (double)value;
+ return size > 0 && !double.IsInfinity(size) && !double.IsNaN(size);
+ });
+
+ private static readonly DependencyPropertyKey ColorTextPropertyKey =
+ DependencyProperty.RegisterReadOnly("ColorText", typeof(string), typeof(ColorPicker),
+ new PropertyMetadata("#FF0000"));
+
+ public static readonly DependencyProperty ColorTextProperty = ColorTextPropertyKey.DependencyProperty;
+
+ public static readonly RoutedEvent SelectedColorChangedEvent =
+ EventManager.RegisterRoutedEvent("SelectedColorChanged", RoutingStrategy.Bubble,
+ typeof(RoutedPropertyChangedEventHandler), typeof(ColorPicker));
+
+ private Popup _popup;
+ private ColorPicker _colorPicker;
+ private ToggleButton _toggleButton;
+ private ComboBox _colorTypeSelector;
+
+ public ColorPicker()
+ {
+ Unloaded += OnUnloaded;
+ IsEnabledChanged += OnIsEnabledChanged;
+ }
+
+ public ColorPickerDisplayMode DisplayMode
+ {
+ get => (ColorPickerDisplayMode)GetValue(DisplayModeProperty);
+ set => SetValue(DisplayModeProperty, value);
+ }
+
+ public bool IsDropDownOpen
+ {
+ get => (bool)GetValue(IsDropDownOpenProperty);
+ set => SetValue(IsDropDownOpenProperty, value);
+ }
+
+ public bool ShowColorText
+ {
+ get => (bool)GetValue(ShowColorTextProperty);
+ set => SetValue(ShowColorTextProperty, value);
+ }
+
+ public double SwatchSize
+ {
+ get => (double)GetValue(SwatchSizeProperty);
+ set => SetValue(SwatchSizeProperty, value);
+ }
+
+ public string ColorText => (string)GetValue(ColorTextProperty);
+
+ public event RoutedPropertyChangedEventHandler SelectedColorChanged
+ {
+ add { AddHandler(SelectedColorChangedEvent, value); }
+ remove { RemoveHandler(SelectedColorChangedEvent, value); }
+ }
+
+ private void DetachPopupTemplate()
+ {
+ DetachColorTypeSelector();
+ if (_popup != null)
+ {
+ _popup.Opened -= OnPopupOpened;
+ _popup.IsOpen = false;
+ }
+ if (_colorPicker != null)
+ {
+ _colorPicker.KeyDown -= OnPickerKeyDown;
+ _colorPicker.SelectedColorChanged -= OnPanelSelectedColorChanged;
+ }
+ }
+
+ private void ApplyPopupTemplate()
+ {
+ _popup = GetTemplateChild(PopupTemplateName) as Popup;
+ _colorPicker = GetTemplateChild(ColorPickerTemplateName) as ColorPicker;
+ _toggleButton = GetTemplateChild(ToggleButtonTemplateName) as ToggleButton;
+ if (_popup != null)
+ _popup.Opened += OnPopupOpened;
+ if (_colorPicker != null)
+ {
+ _colorPicker.KeyDown += OnPickerKeyDown;
+ _colorPicker.SelectedColorChanged += OnPanelSelectedColorChanged;
+ }
+ if (_popup != null && _popup.IsOpen)
+ OnPopupOpened(_popup, System.EventArgs.Empty);
+ }
+
+ protected override void OnKeyDown(KeyEventArgs e)
+ {
+ base.OnKeyDown(e);
+ if (e.Handled || DisplayMode != ColorPickerDisplayMode.Popup)
+ return;
+ if (e.Key == Key.F4 || (e.SystemKey == Key.Down && (Keyboard.Modifiers & ModifierKeys.Alt) != 0))
+ {
+ SetCurrentValue(IsDropDownOpenProperty, !IsDropDownOpen);
+ e.Handled = true;
+ }
+ else if (e.Key == Key.Escape && IsDropDownOpen)
+ {
+ CloseAndFocus();
+ e.Handled = true;
+ }
+ }
+
+ private static void OnDisplayModeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ var picker = (ColorPicker)d;
+ picker.SetCurrentValue(IsDropDownOpenProperty, false);
+ picker.CoerceValue(IsDropDownOpenProperty);
+ }
+
+ private static object CoerceIsDropDownOpen(DependencyObject d, object baseValue)
+ {
+ var picker = (ColorPicker)d;
+ return picker.DisplayMode == ColorPickerDisplayMode.Popup && picker.IsEnabled && (bool)baseValue;
+ }
+
+ private void OnPanelSelectedColorChanged(object sender, RoutedPropertyChangedEventArgs e)
+ {
+ e.Handled = true;
+ }
+
+ private void OnPopupOpened(object sender, System.EventArgs e)
+ {
+ DetachColorTypeSelector();
+ if (_colorPicker != null)
+ {
+ _colorPicker.ApplyTemplate();
+ _colorTypeSelector = _colorPicker.Template?.FindName(
+ ColorPicker.ColorTypeSelectorTemplateName, _colorPicker) as ComboBox;
+ if (_colorTypeSelector != null)
+ {
+ _colorTypeSelector.DropDownOpened += OnFormatDropDownOpened;
+ _colorTypeSelector.DropDownClosed += OnFormatDropDownClosed;
+ }
+ }
+ _colorPicker?.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));
+ }
+
+ private void DetachColorTypeSelector()
+ {
+ if (_colorTypeSelector == null)
+ return;
+ _colorTypeSelector.DropDownOpened -= OnFormatDropDownOpened;
+ _colorTypeSelector.DropDownClosed -= OnFormatDropDownClosed;
+ _colorTypeSelector = null;
+ }
+
+ private void OnFormatDropDownOpened(object sender, System.EventArgs e)
+ {
+ // Let the nested ComboBox own capture until it has finished releasing it.
+ _popup?.SetCurrentValue(Popup.StaysOpenProperty, true);
+ }
+
+ private void OnFormatDropDownClosed(object sender, System.EventArgs e)
+ {
+ var popup = _popup;
+ var selector = _colorTypeSelector;
+ var clickedOutside = _colorPicker != null && !_colorPicker.IsMouseOver &&
+ (Mouse.LeftButton == MouseButtonState.Pressed || Mouse.RightButton == MouseButtonState.Pressed);
+ // DropDownClosed runs before ComboBox releases capture; reclaim it on the next input turn.
+ Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Input, new System.Action(() =>
+ {
+ if (popup == null || popup != _popup || selector != _colorTypeSelector ||
+ (selector != null && selector.IsDropDownOpen))
+ return;
+ popup.SetCurrentValue(Popup.StaysOpenProperty, false);
+ if (clickedOutside)
+ SetCurrentValue(IsDropDownOpenProperty, false);
+ }));
+ }
+
+ private void OnPickerKeyDown(object sender, KeyEventArgs e)
+ {
+ if (!e.Handled && e.Key == Key.Escape)
+ {
+ CloseAndFocus();
+ e.Handled = true;
+ }
+ }
+
+ private void CloseAndFocus()
+ {
+ SetCurrentValue(IsDropDownOpenProperty, false);
+ _toggleButton?.Focus();
+ }
+
+ private void OnUnloaded(object sender, RoutedEventArgs e)
+ {
+ SetCurrentValue(IsDropDownOpenProperty, false);
+ }
+
+ private void OnIsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
+ {
+ if (!(bool)e.NewValue)
+ SetCurrentValue(IsDropDownOpenProperty, false);
+ CoerceValue(IsDropDownOpenProperty);
+ }
+ }
+
+ public enum ColorPickerDisplayMode
+ {
+ Inline,
+ Popup
+ }
+}
diff --git a/src/WPFDevelopers.Shared/Controls/ColorPicker/ColorPicker.cs b/src/WPFDevelopers.Shared/Controls/ColorPicker/ColorPicker.cs
index 32a40e59..827b1058 100644
--- a/src/WPFDevelopers.Shared/Controls/ColorPicker/ColorPicker.cs
+++ b/src/WPFDevelopers.Shared/Controls/ColorPicker/ColorPicker.cs
@@ -11,8 +11,8 @@ namespace WPFDevelopers.Controls
[TemplatePart(Name = HueSliderColorTemplateName, Type = typeof(Slider))]
[TemplatePart(Name = CanvasTemplateName, Type = typeof(Canvas))]
[TemplatePart(Name = ThumbTemplateName, Type = typeof(Thumb))]
- [TemplatePart(Name = ButtonTemplateName, Type = typeof(Button))]
- public class ColorPicker : Control
+ [TemplatePart(Name = ColorTypeSelectorTemplateName, Type = typeof(ComboBox))]
+ public partial class ColorPicker : Control
{
private const string HueSliderColorTemplateName = "PART_HueSlider";
@@ -20,7 +20,7 @@ public class ColorPicker : Control
private const string ThumbTemplateName = "PART_Thumb";
- private const string ButtonTemplateName = "PART_Button";
+ internal const string ColorTypeSelectorTemplateName = "PART_ColorTypeSelector";
private static readonly DependencyPropertyKey HueColorPropertyKey =
DependencyProperty.RegisterReadOnly("HueColor", typeof(Color), typeof(ColorPicker),
@@ -41,9 +41,7 @@ public class ColorPicker : Control
public static readonly DependencyProperty ColorTypeProperty =
DependencyProperty.Register("ColorType", typeof(ColorTypeEnum), typeof(ColorPicker),
- new PropertyMetadata(ColorTypeEnum.RGB));
-
- private Button _button;
+ new FrameworkPropertyMetadata(ColorTypeEnum.RGB, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
private Canvas _canvas;
@@ -51,14 +49,10 @@ public class ColorPicker : Control
private bool _isInnerUpdateSelectedColor;
- private bool _hasPendingSelectedColor;
+ private bool _hasPendingSelectedColor = true;
private Thumb _thumb;
- private ColorTypeEnum[] colorTypeEnums;
-
- private int currentGridStateIndex;
-
static ColorPicker()
{
@@ -85,34 +79,49 @@ public ColorTypeEnum ColorType
private static void OnSelectedColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
- var ctrl = d as ColorPicker;
- if (ctrl._isInnerUpdateSelectedColor)
+ var ctrl = (ColorPicker)d;
+ ctrl.UpdateSelectedColor((Color)e.NewValue);
+ var color = (Color)e.NewValue;
+ ctrl.SetValue(ColorTextPropertyKey, color.A == 255
+ ? $"#{color.R:X2}{color.G:X2}{color.B:X2}"
+ : color.ToString());
+ ctrl.RaiseEvent(new RoutedPropertyChangedEventArgs(
+ (Color)e.OldValue, color, SelectedColorChangedEvent));
+ }
+
+ private void UpdateSelectedColor(Color color)
+ {
+ if (_isInnerUpdateSelectedColor)
{
- ctrl._isInnerUpdateSelectedColor = false;
+ _isInnerUpdateSelectedColor = false;
return;
}
- if (ctrl._hueSliderColor == null)
+ if (_hueSliderColor == null)
{
- ctrl._hasPendingSelectedColor = true;
+ _hasPendingSelectedColor = true;
return;
}
- var color = (Color)e.NewValue;
double h = 0, s = 0, b = 0;
ColorUtil.HsbFromColor(color, ref h, ref s, ref b);
var hsb = new HSB { H = h, S = s, B = b };
- ctrl.SetValue(HueColorPropertyKey, ColorUtil.ColorFromHsb(hsb.H, 1, 1));
- ctrl.SetValue(HSBPropertyKey, hsb);
- ctrl._hueSliderColor.ValueChanged -= ctrl.HueSliderColor_OnValueChanged;
- ctrl._hueSliderColor.Value = 1 - h;
- ctrl._hueSliderColor.ValueChanged += ctrl.HueSliderColor_OnValueChanged;
- ctrl.UpdateThumbPosition();
+ SetValue(HueColorPropertyKey, ColorUtil.ColorFromHsb(hsb.H, 1, 1));
+ SetValue(HSBPropertyKey, hsb);
+ _hueSliderColor.ValueChanged -= HueSliderColor_OnValueChanged;
+ _hueSliderColor.Value = 1 - h;
+ _hueSliderColor.ValueChanged += HueSliderColor_OnValueChanged;
+ UpdateThumbPosition();
}
public override void OnApplyTemplate()
{
- base.OnApplyTemplate();
+ DetachPopupTemplate();
if (_hueSliderColor != null)
_hueSliderColor.ValueChanged -= HueSliderColor_OnValueChanged;
+ if (_canvas != null)
+ _canvas.MouseUp -= Canvas_MouseUp;
+ if (_thumb != null)
+ _thumb.DragDelta -= Thumb_DragDelta;
+ base.OnApplyTemplate();
_canvas = GetTemplateChild(CanvasTemplateName) as Canvas;
if (_canvas != null)
{
@@ -127,18 +136,9 @@ public override void OnApplyTemplate()
if (_hueSliderColor != null)
_hueSliderColor.ValueChanged += HueSliderColor_OnValueChanged;
- _button = GetTemplateChild(ButtonTemplateName) as Button;
- currentGridStateIndex = 0;
- colorTypeEnums = (ColorTypeEnum[])Enum.GetValues(typeof(ColorTypeEnum));
- if (_button != null)
- _button.Click += Button_Click;
+ _hasPendingSelectedColor = true;
LoadedColor();
- }
-
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- currentGridStateIndex = (currentGridStateIndex + 1) % colorTypeEnums.Length;
- ColorType = colorTypeEnums[currentGridStateIndex];
+ ApplyPopupTemplate();
}
private void Canvas_MouseUp(object sender, MouseButtonEventArgs e)
@@ -190,7 +190,7 @@ private void GetHSB(Point point, bool isMove = true)
if (SelectedColor != currentColor)
{
_isInnerUpdateSelectedColor = true;
- SelectedColor = currentColor;
+ SetCurrentValue(SelectedColorProperty, currentColor);
}
}
diff --git a/src/WPFDevelopers.Shared/Controls/DateRangePicker/DateRangePicker.cs b/src/WPFDevelopers.Shared/Controls/DateRangePicker/DateRangePicker.cs
index 00180594..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);
}
@@ -514,8 +529,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 +542,7 @@ private void HandleDateSelection(DateTime clickedDate, bool isStartCalendar)
}
else
{
- clickedDateTime = clickedDate + endTime;
+ clickedDateTime = clickedDate + endTime;
_endDate = clickedDateTime;
if (isStartCalendar)
@@ -571,6 +586,7 @@ private void UpdateEndDateFromTextBox()
if (string.IsNullOrWhiteSpace(_endTextBox.Text))
{
_endDate = null;
+ EndDate = null;
SetIsHighlightFalse(_startCalendarDayButtons);
return;
}
@@ -579,10 +595,19 @@ 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)
{
- 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 +617,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 +644,7 @@ private void UpdateStartDateFromTextBox()
if (string.IsNullOrWhiteSpace(_startTextBox.Text))
{
_startDate = null;
+ StartDate = null;
SetIsHighlightFalse(_startCalendarDayButtons);
return;
}
@@ -618,36 +653,52 @@ private void UpdateStartDateFromTextBox()
{
if (StartDate.HasValue && dateTime.ToString(DateTimeFormat) == StartDate.Value.ToString(DateTimeFormat))
return;
- if (EndDate.HasValue && dateTime < EndDate.Value.Date)
+ if (EndDate.HasValue && dateTime > EndDate.Value)
{
- 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;
}
-
SetIsHighlightFalse(_startCalendarDayButtons);
StartDate = dateTime;
PopupOpened();
}
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;
+ }
}
}
}
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;
@@ -658,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;
@@ -761,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;
@@ -773,17 +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.OriginalSource is Button button)
+ if (e.ChangedButton != MouseButton.Left)
+ return;
+ 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;
@@ -840,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;
}
@@ -945,4 +997,4 @@ private Button GetButtonFromCalendar(Calendar calendar, bool isNext)
return null;
}
}
-}
\ No newline at end of file
+}
diff --git a/src/WPFDevelopers.Shared/Controls/MapView/MapView.cs b/src/WPFDevelopers.Shared/Controls/MapView/MapView.cs
index 57eb1453..10daebb4 100644
--- a/src/WPFDevelopers.Shared/Controls/MapView/MapView.cs
+++ b/src/WPFDevelopers.Shared/Controls/MapView/MapView.cs
@@ -900,6 +900,15 @@ protected override Size ArrangeOverride(Size finalSize)
return finalSize;
}
+ protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
+ {
+ base.OnRenderSizeChanged(sizeInfo);
+ if (_overlayLayer != null)
+ {
+ _overlayLayer.InvalidateVisual();
+ }
+ }
+
private void RefreshOverlay()
{
if (_shapeLayer == null || _itemsLayer == null || _templatedItemsLayer == null || _overlayLayer == null)
diff --git a/src/WPFDevelopers.Shared/Controls/NotifyIcon/NotifyIcon.cs b/src/WPFDevelopers.Shared/Controls/NotifyIcon/NotifyIcon.cs
index c0bb5b02..82eb9e0a 100644
--- a/src/WPFDevelopers.Shared/Controls/NotifyIcon/NotifyIcon.cs
+++ b/src/WPFDevelopers.Shared/Controls/NotifyIcon/NotifyIcon.cs
@@ -126,13 +126,15 @@ private void Resources_ThemeChanged(ThemeType currentTheme)
#if NET40
UpdateDefaultStyle();
#else
- ContextMenu.UpdateDefaultStyle();
+ ContextMenu?.UpdateDefaultStyle();
#endif
}
void UpdateDefaultStyle()
{
var currentContextMenu = ContextMenu;
+ if (currentContextMenu == null) return;
+
var newContextMenu = new ContextMenu();
var itemsToMove = currentContextMenu.Items.OfType().ToList();
currentContextMenu.Items.Clear();
@@ -730,6 +732,14 @@ private void WMMouseDown(MouseButton button, int clicks)
private void OpenMenu()
{
+ if (ContextContent == null && (ContextMenu == null || ContextMenu.Items.Count == 0))
+ return;
+
+ var owner = Window.GetWindow(this) ?? Application.Current?.MainWindow;
+ var ownerHandle = owner != null && owner.IsVisible && owner.WindowState != WindowState.Minimized
+ ? owner.GetHandle()
+ : IntPtr.Zero;
+ var ownerIsForeground = ownerHandle != IntPtr.Zero && User32Interop.SetForegroundWindow(ownerHandle);
if (ContextContent != null)
{
_contextContent = new Popup
@@ -747,12 +757,11 @@ private void OpenMenu()
};
UpdateDataContext(_contextContent, null, DataContext);
_contextContent.IsOpen = true;
- User32Interop.SetForegroundWindow(_contextContent.Child.GetHandle());
+ if (!ownerIsForeground)
+ User32Interop.SetForegroundWindow(_contextContent.Child.GetHandle());
}
else if (ContextMenu != null)
{
- if (ContextMenu.Items.Count == 0) return;
-
ContextMenu.InvalidateProperty(StyleProperty);
foreach (var item in ContextMenu.Items)
if (item is MenuItem menuItem)
@@ -767,7 +776,8 @@ private void OpenMenu()
ContextMenu.Placement = PlacementMode.Mouse;
ContextMenu.IsOpen = true;
- User32Interop.SetForegroundWindow(ContextMenu.GetHandle());
+ if (!ownerIsForeground)
+ User32Interop.SetForegroundWindow(ContextMenu.GetHandle());
}
}
diff --git a/src/WPFDevelopers.Shared/Controls/Panel/WaterfallPanel.cs b/src/WPFDevelopers.Shared/Controls/Panel/WaterfallPanel.cs
deleted file mode 100644
index 1f12fb26..00000000
--- a/src/WPFDevelopers.Shared/Controls/Panel/WaterfallPanel.cs
+++ /dev/null
@@ -1,66 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Windows.Controls;
-using System.Windows;
-
-namespace WPFDevelopers.Controls
-{
- public class WaterfallPanel : VirtualizingPanel
- {
- private List columnHeights = new List();
- protected override Size MeasureOverride(Size availableSize)
- {
- columnHeights.Clear();
- var panelDesiredSize = new Size(0, 0);
- columnHeights = new double[Columns].ToList();
- double currentX = 0;
- var width = availableSize.Width / Columns - (Columns * Spacing);
- for (int i = 0; i < InternalChildren.Count; i++)
- {
- var child = InternalChildren[i] as FrameworkElement;
- if (child == null)
- continue;
- child.Measure(availableSize);
- child.Width = width;
- int columnIndex = i % Columns;
- double x = columnIndex != 0 ? currentX + Spacing : 0;
- double y = columnHeights[columnIndex];
- if (i >= Columns)
- y = y + Spacing;
- var size = new Size(width, child.DesiredSize.Height);
- child.Arrange(new Rect(new Point(x, y), size));
- panelDesiredSize.Width = Math.Max(panelDesiredSize.Width, x + child.DesiredSize.Width);
- panelDesiredSize.Height = Math.Max(panelDesiredSize.Height, y + child.DesiredSize.Height);
- currentX = x + size.Width;
- if (currentX >= Width)
- currentX = 0;
- columnHeights[columnIndex] += child.DesiredSize.Height + (i >= Columns ? Spacing : 0);
- }
- return panelDesiredSize;
- }
-
- public void AddChild(UIElement element)
- {
- Children.Add(element);
- }
-
- public int Columns
- {
- get { return (int)GetValue(ColumnsProperty); }
- set { SetValue(ColumnsProperty, value); }
- }
-
- public static readonly DependencyProperty ColumnsProperty =
- DependencyProperty.Register("Columns", typeof(int), typeof(WaterfallPanel), new PropertyMetadata(3));
-
- public double Spacing
- {
- get { return (double)GetValue(SpacingProperty); }
- set { SetValue(SpacingProperty, value); }
- }
-
- public static readonly DependencyProperty SpacingProperty =
- DependencyProperty.Register("Spacing", typeof(double), typeof(WaterfallPanel), new PropertyMetadata(5.0));
- }
-}
diff --git a/src/WPFDevelopers.Shared/Controls/PathIcon/PackIconKind.cs b/src/WPFDevelopers.Shared/Controls/PathIcon/PackIconKind.cs
index 282476b8..dd4e023a 100644
--- a/src/WPFDevelopers.Shared/Controls/PathIcon/PackIconKind.cs
+++ b/src/WPFDevelopers.Shared/Controls/PathIcon/PackIconKind.cs
@@ -61,5 +61,10 @@ public enum PackIconKind
[Description("WD.CopyGeometry")] Copy,
[Description("WD.UndoGeometry")] Undo,
[Description("WD.FilterGeometry")] Filter,
+ [Description("WD.ConfirmGeometry")] Confirm,
+ [Description("WD.SemicircleGeometry")] Semicircle,
+ [Description("WD.UpArrowGeometry")] UpArrow,
+ [Description("WD.DownArrowGeometry")] DownArrow,
+ [Description("WD.SplitterGeometry")] Splitter,
}
}
diff --git a/src/WPFDevelopers.Shared/Controls/PathIcon/PathIcon.cs b/src/WPFDevelopers.Shared/Controls/PathIcon/PathIcon.cs
index 02364192..567cf359 100644
--- a/src/WPFDevelopers.Shared/Controls/PathIcon/PathIcon.cs
+++ b/src/WPFDevelopers.Shared/Controls/PathIcon/PathIcon.cs
@@ -7,15 +7,15 @@ namespace WPFDevelopers.Controls
public class PathIcon : Control
{
public static readonly DependencyProperty KindProperty =
- DependencyProperty.Register(nameof(Kind), typeof(string), typeof(PathIcon),
- new PropertyMetadata(string.Empty, OnKindChanged));
+ DependencyProperty.Register(nameof(Kind), typeof(PackIconKind?), typeof(PathIcon),
+ new PropertyMetadata(null, OnKindChanged));
public static readonly DependencyProperty DataProperty =
DependencyProperty.Register(nameof(Data), typeof(Geometry), typeof(PathIcon));
- public PackIconKind Kind
+ public PackIconKind? Kind
{
- get { return (PackIconKind)GetValue(KindProperty); }
+ get { return (PackIconKind?)GetValue(KindProperty); }
set { SetValue(KindProperty, value); }
}
@@ -28,14 +28,10 @@ public Geometry Data
private static void OnKindChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var pathIcon = (PathIcon)d;
- var kind = (string)e.NewValue;
- if (!string.IsNullOrWhiteSpace(kind))
- {
- kind = $"WD.{kind}Geometry";
- pathIcon.Data = (Geometry)pathIcon.FindResource(kind);
- }
+ if (e.NewValue is PackIconKind kind)
+ pathIcon.SetResourceReference(DataProperty, $"WD.{kind}Geometry");
else
- pathIcon.Data = null;
+ pathIcon.ClearValue(DataProperty);
}
static PathIcon()
diff --git a/src/WPFDevelopers.Shared/Controls/ScrollViewer/ScrollViewerBehavior.cs b/src/WPFDevelopers.Shared/Controls/ScrollViewer/ScrollViewerBehavior.cs
index d2ed81c7..f8ddf691 100644
--- a/src/WPFDevelopers.Shared/Controls/ScrollViewer/ScrollViewerBehavior.cs
+++ b/src/WPFDevelopers.Shared/Controls/ScrollViewer/ScrollViewerBehavior.cs
@@ -1,5 +1,13 @@
-using System.Windows;
+using System;
+using System.ComponentModel;
+using System.Windows;
+using System.Windows.Automation;
using System.Windows.Controls;
+using System.Windows.Controls.Primitives;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Threading;
+using WPFDevelopers.Helpers;
namespace WPFDevelopers.Controls
{
@@ -19,9 +27,587 @@ public static double GetVerticalOffset(FrameworkElement target)
return (double)target.GetValue(VerticalOffsetProperty);
}
+ public static readonly DependencyProperty IsBackToTopEnabledProperty =
+ DependencyProperty.RegisterAttached(
+ "IsBackToTopEnabled",
+ typeof(bool),
+ typeof(ScrollViewerBehavior),
+ new PropertyMetadata(false, OnIsBackToTopEnabledChanged));
+
+ private static readonly DependencyProperty BackToTopStateProperty =
+ DependencyProperty.RegisterAttached(
+ "BackToTopState",
+ typeof(BackToTopState),
+ typeof(ScrollViewerBehavior),
+ new PropertyMetadata(null));
+
+ public static void SetIsBackToTopEnabled(DependencyObject target, bool value)
+ {
+ target.SetValue(IsBackToTopEnabledProperty, value);
+ }
+
+ public static bool GetIsBackToTopEnabled(DependencyObject target)
+ {
+ return (bool)target.GetValue(IsBackToTopEnabledProperty);
+ }
+
+ public static readonly DependencyProperty IsBackToBottomEnabledProperty =
+ DependencyProperty.RegisterAttached(
+ "IsBackToBottomEnabled",
+ typeof(bool),
+ typeof(ScrollViewerBehavior),
+ new PropertyMetadata(false, OnScrollNavigationChanged));
+
+ public static void SetIsBackToBottomEnabled(DependencyObject target, bool value)
+ {
+ target.SetValue(IsBackToBottomEnabledProperty, value);
+ }
+
+ public static bool GetIsBackToBottomEnabled(DependencyObject target)
+ {
+ return (bool)target.GetValue(IsBackToBottomEnabledProperty);
+ }
+
private static void OnVerticalOffsetChanged(DependencyObject target, DependencyPropertyChangedEventArgs e)
{
(target as WDScrollViewer)?.ScrollToVerticalOffset((double)e.NewValue);
}
+
+ private static void OnIsBackToTopEnabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ OnScrollNavigationChanged(d, e);
+ }
+
+ private static void OnScrollNavigationChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ var target = d as FrameworkElement;
+ if (target == null)
+ return;
+
+ var state = (BackToTopState)target.GetValue(BackToTopStateProperty);
+ if (GetIsBackToTopEnabled(target) || GetIsBackToBottomEnabled(target))
+ {
+ if (state != null)
+ return;
+
+ state = new BackToTopState(target);
+ target.SetValue(BackToTopStateProperty, state);
+ state.Start();
+ }
+ else if (state != null)
+ {
+ state.Stop();
+ target.ClearValue(BackToTopStateProperty);
+ }
+ }
+
+ private static ScrollViewer FindScrollViewer(DependencyObject root)
+ {
+ var scrollViewer = root as ScrollViewer;
+ if (scrollViewer != null)
+ return scrollViewer;
+
+ return FindScrollViewer(root, true) ?? FindScrollViewer(root, false);
+ }
+
+ private static ScrollViewer FindScrollViewer(DependencyObject root, bool requireTemplatePartName)
+ {
+ var count = VisualTreeHelper.GetChildrenCount(root);
+ for (var i = 0; i < count; i++)
+ {
+ var child = VisualTreeHelper.GetChild(root, i);
+ var scrollViewer = child as ScrollViewer;
+ if (scrollViewer != null &&
+ (!requireTemplatePartName || scrollViewer.Name == "PART_ScrollViewer"))
+ {
+ return scrollViewer;
+ }
+
+ scrollViewer = FindScrollViewer(child, requireTemplatePartName);
+ if (scrollViewer != null)
+ return scrollViewer;
+ }
+
+ return null;
+ }
+
+ private sealed class BackToTopState
+ {
+ private readonly FrameworkElement _target;
+ private ScrollViewer _scrollViewer;
+ private Popup _popup;
+ private StackPanel _buttonPanel;
+ private Button _backToTopButton;
+ private Button _backToBottomButton;
+ private Window _ownerWindow;
+ private readonly DispatcherTimer _hideTimer;
+ private DispatcherOperation _openOperation;
+ private DispatcherOperation _revealOperation;
+
+ public BackToTopState(FrameworkElement target)
+ {
+ _target = target;
+ _hideTimer = new DispatcherTimer
+ {
+ Interval = TimeSpan.FromMilliseconds(150)
+ };
+ _hideTimer.Tick += OnHideTimerTick;
+ }
+
+ public void Start()
+ {
+ _target.Loaded += OnTargetLoaded;
+ _target.Unloaded += OnTargetUnloaded;
+ _target.IsVisibleChanged += OnTargetStateChanged;
+ _target.IsEnabledChanged += OnTargetStateChanged;
+ _target.LayoutUpdated += OnTargetLayoutUpdated;
+ _target.SizeChanged += OnTargetSizeChanged;
+ _target.MouseEnter += OnPointerEntered;
+ _target.MouseLeave += OnPointerLeft;
+ _target.IsKeyboardFocusWithinChanged += OnKeyboardFocusWithinChanged;
+
+ if (_target.IsLoaded)
+ Attach();
+ }
+
+ public void Stop()
+ {
+ _target.Loaded -= OnTargetLoaded;
+ _target.Unloaded -= OnTargetUnloaded;
+ _target.IsVisibleChanged -= OnTargetStateChanged;
+ _target.IsEnabledChanged -= OnTargetStateChanged;
+ _target.LayoutUpdated -= OnTargetLayoutUpdated;
+ _target.SizeChanged -= OnTargetSizeChanged;
+ _target.MouseEnter -= OnPointerEntered;
+ _target.MouseLeave -= OnPointerLeft;
+ _target.IsKeyboardFocusWithinChanged -= OnKeyboardFocusWithinChanged;
+ Detach();
+ }
+
+ private void OnTargetLoaded(object sender, RoutedEventArgs e)
+ {
+ Attach();
+ }
+
+ private void OnTargetUnloaded(object sender, RoutedEventArgs e)
+ {
+ Detach();
+ }
+
+ private void OnTargetStateChanged(object sender, DependencyPropertyChangedEventArgs e)
+ {
+ UpdateButton();
+ }
+
+ private void OnTargetLayoutUpdated(object sender, EventArgs e)
+ {
+ if (_scrollViewer == null)
+ Attach();
+ }
+
+ private void OnTargetSizeChanged(object sender, SizeChangedEventArgs e)
+ {
+ UpdateButton();
+ }
+
+ private void OnPointerEntered(object sender, MouseEventArgs e)
+ {
+ _hideTimer.Stop();
+ UpdateButton();
+ }
+
+ private void OnPointerLeft(object sender, MouseEventArgs e)
+ {
+ ScheduleHide();
+ }
+
+ private void OnKeyboardFocusWithinChanged(object sender, DependencyPropertyChangedEventArgs e)
+ {
+ if ((bool)e.NewValue)
+ {
+ _hideTimer.Stop();
+ UpdateButton();
+ }
+ else
+ {
+ ScheduleHide();
+ }
+ }
+
+ private void Attach()
+ {
+ Detach();
+
+ var control = _target as Control;
+ if (control != null)
+ control.ApplyTemplate();
+
+ _scrollViewer = FindScrollViewer(_target);
+ if (_scrollViewer == null)
+ {
+ _target.LayoutUpdated -= OnTargetLayoutUpdated;
+ _target.LayoutUpdated += OnTargetLayoutUpdated;
+ return;
+ }
+
+ _target.LayoutUpdated -= OnTargetLayoutUpdated;
+
+ _backToTopButton = GetIsBackToTopEnabled(_target)
+ ? CreateNavigationButton("BackToTop", PackIconKind.UpArrow, ScrollToTop)
+ : null;
+ _backToBottomButton = GetIsBackToBottomEnabled(_target)
+ ? CreateNavigationButton("BackToBottom", PackIconKind.DownArrow, ScrollToBottom)
+ : null;
+ _buttonPanel = new StackPanel
+ {
+ Orientation = Orientation.Horizontal
+ };
+ _buttonPanel.MouseEnter += OnPointerEntered;
+ _buttonPanel.MouseLeave += OnPointerLeft;
+ _buttonPanel.IsKeyboardFocusWithinChanged += OnKeyboardFocusWithinChanged;
+ if (_backToTopButton != null)
+ _buttonPanel.Children.Add(_backToTopButton);
+ if (_backToBottomButton != null)
+ {
+ if (_backToTopButton != null)
+ _backToBottomButton.Margin = new Thickness(6, 0, 0, 0);
+ _buttonPanel.Children.Add(_backToBottomButton);
+ }
+
+ _popup = new Popup
+ {
+ AllowsTransparency = true,
+ Placement = PlacementMode.Relative,
+ PlacementTarget = _target,
+ StaysOpen = true,
+ Child = _buttonPanel
+ };
+ AttachOwnerWindow();
+ _scrollViewer.ScrollChanged += OnScrollChanged;
+ LanguageManager.Instance.PropertyChanged += OnLanguagePropertyChanged;
+ UpdateButton();
+ }
+
+ private void Detach()
+ {
+ _hideTimer.Stop();
+ CancelPendingPopupOperations();
+
+ if (_scrollViewer != null)
+ _scrollViewer.ScrollChanged -= OnScrollChanged;
+
+ LanguageManager.Instance.PropertyChanged -= OnLanguagePropertyChanged;
+
+ if (_popup != null)
+ _popup.IsOpen = false;
+
+ if (_buttonPanel != null)
+ {
+ _buttonPanel.MouseEnter -= OnPointerEntered;
+ _buttonPanel.MouseLeave -= OnPointerLeft;
+ _buttonPanel.IsKeyboardFocusWithinChanged -= OnKeyboardFocusWithinChanged;
+ }
+
+ DetachOwnerWindow();
+ _scrollViewer = null;
+ _popup = null;
+ _buttonPanel = null;
+ _backToTopButton = null;
+ _backToBottomButton = null;
+ }
+
+ private void AttachOwnerWindow()
+ {
+ _ownerWindow = Window.GetWindow(_target);
+ if (_ownerWindow == null)
+ return;
+
+ _ownerWindow.StateChanged += OnOwnerWindowStateChanged;
+ _ownerWindow.IsVisibleChanged += OnOwnerWindowIsVisibleChanged;
+ _ownerWindow.Activated += OnOwnerWindowActivated;
+ _ownerWindow.Deactivated += OnOwnerWindowDeactivated;
+ _ownerWindow.Closed += OnOwnerWindowClosed;
+ }
+
+ private void DetachOwnerWindow()
+ {
+ if (_ownerWindow == null)
+ return;
+
+ _ownerWindow.StateChanged -= OnOwnerWindowStateChanged;
+ _ownerWindow.IsVisibleChanged -= OnOwnerWindowIsVisibleChanged;
+ _ownerWindow.Activated -= OnOwnerWindowActivated;
+ _ownerWindow.Deactivated -= OnOwnerWindowDeactivated;
+ _ownerWindow.Closed -= OnOwnerWindowClosed;
+ _ownerWindow = null;
+ }
+
+ private void OnOwnerWindowStateChanged(object sender, EventArgs e)
+ {
+ UpdateButton();
+ }
+
+ private void OnOwnerWindowIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
+ {
+ UpdateButton();
+ }
+
+ private void OnOwnerWindowActivated(object sender, EventArgs e)
+ {
+ UpdateButton();
+ }
+
+ private void OnOwnerWindowDeactivated(object sender, EventArgs e)
+ {
+ _hideTimer.Stop();
+ ClosePopup();
+ }
+
+ private void OnOwnerWindowClosed(object sender, EventArgs e)
+ {
+ _hideTimer.Stop();
+ ClosePopup();
+ }
+
+ private void OnScrollChanged(object sender, ScrollChangedEventArgs e)
+ {
+ UpdateButton();
+ }
+
+ private void OnLanguagePropertyChanged(object sender, PropertyChangedEventArgs e)
+ {
+ if (_buttonPanel == null)
+ return;
+
+ UpdateLocalizedText();
+ }
+
+ private void UpdateButton()
+ {
+ if (_popup == null || _buttonPanel == null || _scrollViewer == null)
+ return;
+
+ if (!_target.IsLoaded ||
+ _target.ActualWidth <= 0 ||
+ _target.ActualHeight <= 0 ||
+ PresentationSource.FromVisual(_target) == null)
+ {
+ _hideTimer.Stop();
+ ClosePopup();
+ return;
+ }
+
+ if (_backToTopButton != null)
+ _backToTopButton.Visibility = _scrollViewer.VerticalOffset > 0
+ ? Visibility.Visible
+ : Visibility.Collapsed;
+ if (_backToBottomButton != null)
+ _backToBottomButton.Visibility = _scrollViewer.VerticalOffset <
+ _scrollViewer.ScrollableHeight
+ ? Visibility.Visible
+ : Visibility.Collapsed;
+
+ if (_backToTopButton != null)
+ _backToTopButton.IsEnabled = _target.IsEnabled;
+ if (_backToBottomButton != null)
+ _backToBottomButton.IsEnabled = _target.IsEnabled;
+ var visibleButtonCount = (_backToTopButton != null &&
+ _backToTopButton.Visibility == Visibility.Visible ? 1 : 0) +
+ (_backToBottomButton != null &&
+ _backToBottomButton.Visibility == Visibility.Visible ? 1 : 0);
+ UpdatePopupOffsets(visibleButtonCount);
+ var isOwnerWindowVisible = _ownerWindow == null ||
+ (_ownerWindow.IsVisible &&
+ _ownerWindow.IsActive &&
+ _ownerWindow.WindowState != WindowState.Minimized);
+ var shouldOpen = _target.IsVisible &&
+ isOwnerWindowVisible &&
+ IsInteractionActive() &&
+ visibleButtonCount > 0;
+ if (!shouldOpen)
+ {
+ 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()
+ {
+ return _target.IsMouseOver ||
+ _target.IsKeyboardFocusWithin ||
+ (_buttonPanel != null &&
+ (_buttonPanel.IsMouseOver || _buttonPanel.IsKeyboardFocusWithin));
+ }
+
+ private void ScheduleHide()
+ {
+ _hideTimer.Stop();
+ _hideTimer.Start();
+ }
+
+ private void OnHideTimerTick(object sender, EventArgs e)
+ {
+ _hideTimer.Stop();
+ UpdateButton();
+ }
+
+ private void ScrollToTop()
+ {
+ var animatedScrollViewer = _scrollViewer as WDScrollViewer;
+ if (animatedScrollViewer != null && animatedScrollViewer.IsScrollAnimation)
+ animatedScrollViewer.AnimateScroll(0);
+ else
+ _scrollViewer.ScrollToTop();
+ }
+
+ private Button CreateNavigationButton(string resourceKey, PackIconKind iconKind, Action clickHandler)
+ {
+ var text = LanguageManager.Instance[resourceKey];
+ var button = new Button
+ {
+ Width = 36,
+ Height = 36,
+ ToolTip = text,
+ Content = new PathIcon
+ {
+ Width = 18,
+ Height = 18,
+ Kind = iconKind,
+ }
+ };
+ ElementHelper.SetIsRound(button, true);
+ button.SetResourceReference(FrameworkElement.StyleProperty, "WD.DefaultButton");
+ AutomationProperties.SetName(button, text);
+ button.Click += (sender, e) => clickHandler();
+ return button;
+ }
+
+ private void UpdateLocalizedText()
+ {
+ UpdateButtonText(_backToTopButton, "BackToTop");
+ UpdateButtonText(_backToBottomButton, "BackToBottom");
+ }
+
+ private static void UpdateButtonText(Button button, string resourceKey)
+ {
+ if (button == null)
+ return;
+
+ var text = LanguageManager.Instance[resourceKey];
+ button.ToolTip = text;
+ AutomationProperties.SetName(button, text);
+ }
+
+ private void ScrollToBottom()
+ {
+ var animatedScrollViewer = _scrollViewer as WDScrollViewer;
+ if (animatedScrollViewer != null && animatedScrollViewer.IsScrollAnimation)
+ animatedScrollViewer.AnimateScroll(_scrollViewer.ScrollableHeight);
+ else
+ _scrollViewer.ScrollToEnd();
+ }
+ }
}
-}
\ No newline at end of file
+}
diff --git a/src/WPFDevelopers.Shared/Controls/ScrollViewer/WDScrollViewer.cs b/src/WPFDevelopers.Shared/Controls/ScrollViewer/WDScrollViewer.cs
index 76f1ae4e..510302ef 100644
--- a/src/WPFDevelopers.Shared/Controls/ScrollViewer/WDScrollViewer.cs
+++ b/src/WPFDevelopers.Shared/Controls/ScrollViewer/WDScrollViewer.cs
@@ -8,7 +8,9 @@ namespace WPFDevelopers.Controls
{
public class WDScrollViewer : ScrollViewer
{
- private static double _lastLocation;
+ private double _animationTarget;
+ private bool _isAnimating;
+ private int _animationVersion;
public bool IsScrollAnimation
{
@@ -23,21 +25,8 @@ private static void OnIsScrollAnimationChanged(DependencyObject d, DependencyPro
{
var ctrl = d as WDScrollViewer;
if (ctrl == null) return;
- if (ctrl.IsScrollAnimation)
- {
- ctrl.ScrollChanged -= OnScrollChanged;
- ctrl.ScrollChanged += OnScrollChanged;
- }
- else
- ctrl.ScrollChanged -= OnScrollChanged;
- }
-
- private static void OnScrollChanged(object sender, ScrollChangedEventArgs e)
- {
- var ctrl = sender as WDScrollViewer;
- if (ctrl == null) return;
- if (e.VerticalChange != 0)
- _lastLocation = ctrl.VerticalOffset;
+ if (!ctrl.IsScrollAnimation)
+ ctrl.StopScrollAnimation();
}
protected override void OnMouseWheel(MouseWheelEventArgs e)
@@ -47,31 +36,68 @@ protected override void OnMouseWheel(MouseWheelEventArgs e)
base.OnMouseWheel(e);
return;
}
- var WheelChange = e.Delta;
- var newOffset = _lastLocation - WheelChange * 2;
- ScrollToVerticalOffset(_lastLocation);
- if (newOffset < 0)
- newOffset = 0;
- if (newOffset > ScrollableHeight)
- newOffset = ScrollableHeight;
+ if (e.Handled)
+ return;
+ var change = -e.Delta * 2.0;
+ var start = _isAnimating && (_animationTarget - VerticalOffset) * change > 0
+ ? _animationTarget
+ : VerticalOffset;
+ var newOffset = Math.Max(0, Math.Min(start + change, ScrollableHeight));
AnimateScroll(newOffset);
- _lastLocation = newOffset;
e.Handled = true;
}
public void AnimateScroll(double toValue, Action onCompleted = null)
{
- BeginAnimation(ScrollViewerBehavior.VerticalOffsetProperty, null);
+ if (double.IsNaN(toValue))
+ throw new ArgumentOutOfRangeException("toValue");
+
+ var from = VerticalOffset;
+ _animationTarget = Math.Max(0, Math.Min(toValue, ScrollableHeight));
+ _isAnimating = true;
+ var version = ++_animationVersion;
var animation = new DoubleAnimation
{
EasingFunction = new CubicEase { EasingMode = EasingMode.EaseOut },
- From = VerticalOffset,
- To = toValue,
- Duration = TimeSpan.FromMilliseconds(800)
+ From = from,
+ To = _animationTarget,
+ Duration = TimeSpan.FromMilliseconds(250)
+ };
+ animation.Completed += (s, e) =>
+ {
+ if (version != _animationVersion)
+ return;
+ var target = _animationTarget;
+ StopScrollAnimation();
+ ScrollToVerticalOffset(target);
+ onCompleted?.Invoke();
};
- Timeline.SetDesiredFrameRate(animation, 40);
- animation.Completed += (s, e) => onCompleted?.Invoke();
- BeginAnimation(ScrollViewerBehavior.VerticalOffsetProperty, animation);
+ BeginAnimation(ScrollViewerBehavior.VerticalOffsetProperty, animation,
+ HandoffBehavior.SnapshotAndReplace);
+ }
+
+ private void StopScrollAnimation()
+ {
+ ++_animationVersion;
+ _isAnimating = false;
+ SetValue(ScrollViewerBehavior.VerticalOffsetProperty, VerticalOffset);
+ BeginAnimation(ScrollViewerBehavior.VerticalOffsetProperty, null);
+ }
+
+ protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
+ {
+ if (_isAnimating)
+ StopScrollAnimation();
+ base.OnPreviewMouseDown(e);
+ }
+
+ protected override void OnPreviewKeyDown(KeyEventArgs e)
+ {
+ if (_isAnimating && (e.Key == Key.Up || e.Key == Key.Down ||
+ e.Key == Key.PageUp || e.Key == Key.PageDown ||
+ e.Key == Key.Home || e.Key == Key.End))
+ StopScrollAnimation();
+ base.OnPreviewKeyDown(e);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/WPFDevelopers.Shared/Controls/Segmented/Segmented.cs b/src/WPFDevelopers.Shared/Controls/Segmented/Segmented.cs
index 584c8ceb..7a4b79d8 100644
--- a/src/WPFDevelopers.Shared/Controls/Segmented/Segmented.cs
+++ b/src/WPFDevelopers.Shared/Controls/Segmented/Segmented.cs
@@ -104,28 +104,27 @@ public override void OnApplyTemplate()
_indicator = GetTemplateChild(IndicatorTemplateName) as Border;
_indicatorTransform = GetTemplateChild(IndicatorTransformTemplateName) as TranslateTransform;
_itemsPresenter = GetTemplateChild(ItemsPresenterTemplateName) as FrameworkElement;
+ SizeChanged -= Segmented_SizeChanged;
SizeChanged += Segmented_SizeChanged;
}
private void Segmented_SizeChanged(object sender, SizeChangedEventArgs e)
{
if (SelectedIndex >= 0)
- AnimateIndicator(SelectedIndex, false);
+ QueueIndicatorUpdate(false);
}
protected override void OnSelectedIndexChanged(int oldIndex, int newIndex)
{
base.OnSelectedIndexChanged(oldIndex, newIndex);
- Dispatcher.BeginInvoke(new Action(() => AnimateIndicator(newIndex)),
- System.Windows.Threading.DispatcherPriority.Render);
+ QueueIndicatorUpdate();
}
private static void OnOrientationChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var ctrl = (Segmented)d;
if (ctrl.SelectedIndex >= 0)
- ctrl.Dispatcher.BeginInvoke(new Action(() => ctrl.AnimateIndicator(ctrl.SelectedIndex, false)),
- System.Windows.Threading.DispatcherPriority.Render);
+ ctrl.QueueIndicatorUpdate(false);
}
private void ItemContainerGenerator_StatusChanged(object sender, EventArgs e)
@@ -133,8 +132,7 @@ private void ItemContainerGenerator_StatusChanged(object sender, EventArgs e)
if (ItemContainerGenerator.Status == System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated)
{
SyncSelectedIndexToContainer();
- Dispatcher.BeginInvoke(new Action(() => AnimateIndicator(SelectedIndex, false)),
- System.Windows.Threading.DispatcherPriority.Loaded);
+ QueueIndicatorUpdate(false);
}
}
@@ -147,12 +145,17 @@ private void Container_Checked(object sender, RoutedEventArgs e)
if (idx >= 0)
{
SyncSelectedIndex(idx);
- Dispatcher.BeginInvoke(new Action(() => AnimateIndicator(idx)),
- System.Windows.Threading.DispatcherPriority.Render);
+ QueueIndicatorUpdate();
RaiseItemClick(container.Content);
}
}
+ private void QueueIndicatorUpdate(bool animate = true)
+ {
+ Dispatcher.BeginInvoke(new Action(() => AnimateIndicator(SelectedIndex, animate)),
+ System.Windows.Threading.DispatcherPriority.Loaded);
+ }
+
private void SyncSelectedIndexToContainer()
{
var index = SelectedIndex;
@@ -188,6 +191,7 @@ private void AnimateIndicator(int index, bool animate = true)
_indicator.Height = double.NaN;
_indicator.HorizontalAlignment = HorizontalAlignment.Left;
_indicator.VerticalAlignment = VerticalAlignment.Stretch;
+ _indicatorTransform.BeginAnimation(TranslateTransform.YProperty, null);
if (animate)
{
var anim = new DoubleAnimation(pos.X, TimeSpan.FromSeconds(AnimationDuration))
@@ -198,6 +202,7 @@ private void AnimateIndicator(int index, bool animate = true)
}
else
{
+ _indicatorTransform.BeginAnimation(TranslateTransform.XProperty, null);
_indicatorTransform.X = pos.X;
}
}
@@ -207,6 +212,7 @@ private void AnimateIndicator(int index, bool animate = true)
_indicator.Height = container.ActualHeight;
_indicator.HorizontalAlignment = HorizontalAlignment.Stretch;
_indicator.VerticalAlignment = VerticalAlignment.Top;
+ _indicatorTransform.BeginAnimation(TranslateTransform.XProperty, null);
if (animate)
{
var anim = new DoubleAnimation(pos.Y, TimeSpan.FromSeconds(AnimationDuration))
@@ -217,6 +223,7 @@ private void AnimateIndicator(int index, bool animate = true)
}
else
{
+ _indicatorTransform.BeginAnimation(TranslateTransform.YProperty, null);
_indicatorTransform.Y = pos.Y;
}
}
diff --git a/src/WPFDevelopers.Shared/Controls/SvgViewer/SvgViewer.cs b/src/WPFDevelopers.Shared/Controls/SvgViewer/SvgViewer.cs
index 20600764..22174d1e 100644
--- a/src/WPFDevelopers.Shared/Controls/SvgViewer/SvgViewer.cs
+++ b/src/WPFDevelopers.Shared/Controls/SvgViewer/SvgViewer.cs
@@ -12,6 +12,7 @@ namespace WPFDevelopers.Controls
public class SvgViewer : Control
{
private DrawingBrush _svgBrush;
+ private bool _usesCurrentColor;
public string Source
{
get => (string)GetValue(SourceProperty);
@@ -34,6 +35,11 @@ private Brush ParseBrush(string value)
{
if (string.IsNullOrWhiteSpace(value) || value == "none")
return null;
+ if (string.Equals(value, "currentColor", StringComparison.OrdinalIgnoreCase))
+ {
+ _usesCurrentColor = true;
+ return Foreground?.CloneCurrentValue();
+ }
try
{
@@ -266,6 +272,7 @@ private void CreateDrawingBrush(DrawingGroup drawingGroup, Rect bounds)
private void LoadAndRenderSvg()
{
+ _usesCurrentColor = false;
if (string.IsNullOrWhiteSpace(Source)) return;
var extension = Path.GetExtension(Source)?.ToLower();
if (extension != ".svg")
@@ -359,8 +366,16 @@ private string RemoveDoctype(string xmlContent)
static SvgViewer()
{
+ ForegroundProperty.OverrideMetadata(typeof(SvgViewer), new FrameworkPropertyMetadata(OnForegroundChanged));
DefaultStyleKeyProperty.OverrideMetadata(typeof(SvgViewer), new FrameworkPropertyMetadata(typeof(SvgViewer)));
}
+
+ private static void OnForegroundChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ if (d is SvgViewer viewer && viewer._usesCurrentColor && !string.IsNullOrWhiteSpace(viewer.Source))
+ viewer.LoadAndRenderSvg();
+ }
+
protected override void OnRender(DrawingContext dc)
{
base.OnRender(dc);
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/Controls/TimePicker/TimePicker.cs b/src/WPFDevelopers.Shared/Controls/TimePicker/TimePicker.cs
index e4892295..674438b2 100644
--- a/src/WPFDevelopers.Shared/Controls/TimePicker/TimePicker.cs
+++ b/src/WPFDevelopers.Shared/Controls/TimePicker/TimePicker.cs
@@ -1,4 +1,7 @@
using System;
+using System.Globalization;
+using System.Linq;
+using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
@@ -10,11 +13,15 @@ namespace WPFDevelopers.Controls
[TemplatePart(Name = TimeSelectorTemplateName, Type = typeof(ListBox))]
[TemplatePart(Name = EditableTextBoxTemplateName, Type = typeof(TextBox))]
[TemplatePart(Name = PopupTemplateName, Type = typeof(Popup))]
+ [TemplatePart(Name = ButtonConfirmTemplateName, Type = typeof(Button))]
+ [TemplatePart(Name = ButtonCancelTemplateName, Type = typeof(Button))]
public class TimePicker : Control
{
private const string TimeSelectorTemplateName = "PART_TimeSelector";
private const string EditableTextBoxTemplateName = "PART_EditableTextBox";
private const string PopupTemplateName = "PART_Popup";
+ private const string ButtonConfirmTemplateName = "PART_ButtonConfirm";
+ private const string ButtonCancelTemplateName = "PART_ButtonCancel";
public static readonly DependencyProperty IsDropDownOpenProperty =
DependencyProperty.Register("IsDropDownOpen", typeof(bool), typeof(TimePicker),
@@ -22,7 +29,7 @@ public class TimePicker : Control
public static readonly DependencyProperty SelectedTimeFormatProperty =
DependencyProperty.Register("SelectedTimeFormat", typeof(string), typeof(TimePicker),
- new PropertyMetadata("HH:mm:ss"));
+ new PropertyMetadata("HH:mm:ss", OnSelectedTimeFormatChanged));
public static readonly DependencyProperty MaxDropDownHeightProperty =
DependencyProperty.Register("MaxDropDownHeight", typeof(double), typeof(TimePicker),
@@ -46,6 +53,9 @@ public class TimePicker : Control
private Popup _popup;
private TextBox _textBox;
private TimeSelector _timeSelector;
+ private Button _buttonConfirm;
+ private Button _buttonCancel;
+ private bool _isSelectingTime;
static TimePicker()
{
@@ -90,6 +100,125 @@ private static void OnMaxDropDownHeightChanged(DependencyObject d, DependencyPro
ctrl.OnMaxDropDownHeightChanged((double)e.OldValue, (double)e.NewValue);
}
+ private static void OnSelectedTimeFormatChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ var ctrl = d as TimePicker;
+ if (ctrl == null)
+ return;
+
+ if (ctrl._timeSelector != null)
+ {
+ ctrl._timeSelector.IsTwelveHourFormat = UsesTwelveHourFormat((string)e.NewValue);
+ ctrl._timeSelector.ShowSeconds = UsesSecondsFormat((string)e.NewValue);
+ ctrl._timeSelector.SetTime();
+ }
+ if (ctrl._textBox != null)
+ {
+ ctrl._textBox.TextChanged -= ctrl.TextBox_TextChanged;
+ ctrl._textBox.Text = ctrl.SelectedTime.HasValue
+ ? ctrl.SelectedTime.Value.ToString(GetDisplayTimeFormat((string)e.NewValue))
+ : string.Empty;
+ ctrl._textBox.TextChanged += ctrl.TextBox_TextChanged;
+ }
+ }
+
+ private static bool UsesTwelveHourFormat(string format)
+ {
+ return ContainsFormatSpecifier(format, 'h')
+ && !ContainsFormatSpecifier(format, 'H');
+ }
+
+ private static string GetDisplayTimeFormat(string format)
+ {
+ if (string.IsNullOrEmpty(format) || UsesTwelveHourFormat(format) || format.Length == 1)
+ return format;
+
+ var result = new StringBuilder(format.Length);
+ char quote = '\0';
+ for (int i = 0; i < format.Length; i++)
+ {
+ var character = format[i];
+ if (character == '\\')
+ {
+ result.Append(character);
+ if (i + 1 < format.Length)
+ result.Append(format[++i]);
+ continue;
+ }
+ if (quote != '\0')
+ {
+ result.Append(character);
+ if (character == quote)
+ quote = '\0';
+ continue;
+ }
+ if (character == '\'' || character == '"')
+ {
+ quote = character;
+ result.Append(character);
+ continue;
+ }
+ if (character == 't')
+ {
+ while (result.Length > 0 && char.IsWhiteSpace(result[result.Length - 1]))
+ result.Length--;
+ while (i + 1 < format.Length && format[i + 1] == 't')
+ i++;
+ while (i + 1 < format.Length && char.IsWhiteSpace(format[i + 1]))
+ i++;
+ continue;
+ }
+ result.Append(character);
+ }
+ return result.ToString().TrimEnd();
+ }
+
+ private static bool UsesSecondsFormat(string format)
+ {
+ if (format == "T")
+ return ContainsFormatSpecifier(CultureInfo.CurrentCulture.DateTimeFormat.LongTimePattern, 's');
+ if (format == "t")
+ return ContainsFormatSpecifier(CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern, 's');
+ return ContainsFormatSpecifier(format, 's');
+ }
+
+ private static bool ContainsFormatSpecifier(string format, char specifier)
+ {
+ if (string.IsNullOrEmpty(format))
+ return false;
+
+ char quote = '\0';
+ bool isEscaped = false;
+ foreach (var character in format)
+ {
+ if (isEscaped)
+ {
+ isEscaped = false;
+ continue;
+ }
+ if (character == '\\')
+ {
+ isEscaped = true;
+ continue;
+ }
+ if (quote != '\0')
+ {
+ if (character == quote)
+ quote = '\0';
+ continue;
+ }
+ if (character == '\'' || character == '"')
+ {
+ quote = character;
+ continue;
+ }
+ if (character == specifier)
+ return true;
+ }
+
+ return false;
+ }
+
protected virtual void OnMaxDropDownHeightChanged(double oldValue, double newValue)
{
}
@@ -111,6 +240,14 @@ private static void OnSelectedTimeChanged(DependencyObject d, DependencyProperty
else
ctrl._date = dateTime.Value;
}
+ if (ctrl._buttonConfirm != null && ctrl._textBox != null)
+ {
+ ctrl._textBox.TextChanged -= ctrl.TextBox_TextChanged;
+ ctrl._textBox.Text = ctrl.SelectedTime.HasValue
+ ? ctrl.SelectedTime.Value.ToString(GetDisplayTimeFormat(ctrl.SelectedTimeFormat))
+ : string.Empty;
+ ctrl._textBox.TextChanged += ctrl.TextBox_TextChanged;
+ }
ctrl.RaiseSelectedTimeChangedEvent(e.OldValue as DateTime?, e.NewValue as DateTime?);
}
}
@@ -128,21 +265,54 @@ public override void OnApplyTemplate()
_window = Window.GetWindow(this);
if (_window != null)
_popupWindowHook = new PopupWindowHook(_window, () => IsDropDownOpen = false);
+
+ if (_buttonConfirm != null)
+ _buttonConfirm.Click -= OnButtonConfirm_Click;
+ if (_buttonCancel != null)
+ _buttonCancel.Click -= OnButtonCancel_Click;
+ _isSelectingTime = false;
+
_textBox = GetTemplateChild(EditableTextBoxTemplateName) as TextBox;
if (_textBox != null)
+ {
+ _textBox.TextChanged -= TextBox_TextChanged;
+ _textBox.PreviewTextInput -= TextBox_PreviewTextInput;
+ _textBox.PreviewKeyDown -= TextBox_PreviewKeyDown;
+ DataObject.RemovePastingHandler(_textBox, TextBox_Pasting);
+
+ _textBox.Text = SelectedTime.HasValue
+ ? SelectedTime.Value.ToString(GetDisplayTimeFormat(SelectedTimeFormat))
+ : string.Empty;
+
_textBox.TextChanged += TextBox_TextChanged;
+ _textBox.PreviewTextInput += TextBox_PreviewTextInput;
+ _textBox.PreviewKeyDown += TextBox_PreviewKeyDown;
+ DataObject.AddPastingHandler(_textBox, TextBox_Pasting);
+ }
+ _buttonConfirm = GetTemplateChild(ButtonConfirmTemplateName) as Button;
+ if (_buttonConfirm != null)
+ _buttonConfirm.Click += OnButtonConfirm_Click;
+ _buttonCancel = GetTemplateChild(ButtonCancelTemplateName) as Button;
+ if (_buttonCancel != null)
+ _buttonCancel.Click += OnButtonCancel_Click;
+
_timeSelector = GetTemplateChild(TimeSelectorTemplateName) as TimeSelector;
if (_timeSelector != null)
{
+ _timeSelector.IsTwelveHourFormat = UsesTwelveHourFormat(SelectedTimeFormat);
+ _timeSelector.ShowSeconds = UsesSecondsFormat(SelectedTimeFormat);
_timeSelector.SelectedTimeChanged -= OnTimeSelector_SelectedTimeChanged;
_timeSelector.SelectedTimeChanged += OnTimeSelector_SelectedTimeChanged;
if (!SelectedTime.HasValue && IsCurrentTime)
{
SelectedTime = DateTime.Now;
}
- else
+ else if (SelectedTime.HasValue)
+ {
+ _timeSelector.SelectedTime = SelectedTime;
+ }
+ else if (_date > DateTime.MinValue)
{
- SelectedTime = null;
SelectedTime = _date;
}
}
@@ -152,19 +322,59 @@ public override void OnApplyTemplate()
{
_popup.Opened -= OnPopup_Opened;
_popup.Opened += OnPopup_Opened;
+ _popup.Closed += OnPopup_Closed;
+ }
+ }
+
+ private static void TextBox_Pasting(object sender, DataObjectPastingEventArgs e)
+ {
+ if (e.DataObject.GetDataPresent(typeof(string)))
+ {
+ var text = e.DataObject.GetData(typeof(string)) as string;
+ if (!string.IsNullOrEmpty(text) && !IsAllowedTimeText(text))
+ e.CancelCommand();
}
+ else
+ {
+ e.CancelCommand();
+ }
+ }
+
+ private static void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
+ {
+ if (!string.IsNullOrEmpty(e.Text) && !IsAllowedTimeText(e.Text))
+ e.Handled = true;
+ }
+
+ private static void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
+ {
+ if (e.Key == Key.Space)
+ e.Handled = true;
+ }
+
+ private static bool IsAllowedTimeText(string text)
+ {
+ return text.All(c => char.IsDigit(c) || c == ':');
}
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
if (_textBox != null)
{
+ var text = _textBox.Text ?? string.Empty;
+ var sanitizedText = new string(text.Where(c => char.IsDigit(c) || c == ':').ToArray());
+ if (sanitizedText != text)
+ _textBox.Text = sanitizedText;
+
+ if (_timeSelector == null)
+ return;
+
_timeSelector.SelectedTimeChanged -= OnTimeSelector_SelectedTimeChanged;
if (DateTime.TryParse(_textBox.Text, out var dateTime))
{
if (SelectedTime.HasValue
&&
- dateTime.ToString(SelectedTimeFormat) == SelectedTime.Value.ToString(SelectedTimeFormat))
+ dateTime.ToString(GetDisplayTimeFormat(SelectedTimeFormat)) == SelectedTime.Value.ToString(GetDisplayTimeFormat(SelectedTimeFormat)))
{
_timeSelector.SelectedTimeChanged += OnTimeSelector_SelectedTimeChanged;
return;
@@ -179,23 +389,74 @@ private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
private void OnPopup_Opened(object sender, EventArgs e)
{
- _window.PreviewMouseDown += OnWindowPreviewMouseDown;
+ _isSelectingTime = _buttonConfirm != null;
+ if (_window != null)
+ _window.PreviewMouseDown += OnWindowPreviewMouseDown;
if (_timeSelector != null)
+ {
+ if (_isSelectingTime)
+ _timeSelector.SelectedTime = SelectedTime ?? DateTime.Now;
_timeSelector.SetTime();
+ }
+ }
+
+ private void OnPopup_Closed(object sender, EventArgs e)
+ {
+ if (_window != null)
+ _window.PreviewMouseDown -= OnWindowPreviewMouseDown;
+ if (_isSelectingTime && _timeSelector != null)
+ _timeSelector.SelectedTime = SelectedTime;
+ _isSelectingTime = false;
+ }
+
+ private void OnButtonConfirm_Click(object sender, RoutedEventArgs e)
+ {
+ if (_timeSelector != null && _timeSelector.SelectedTime.HasValue)
+ {
+ var selectedTime = _timeSelector.SelectedTime.Value;
+ if (SelectedTime.HasValue)
+ selectedTime = SelectedTime.Value.Date + selectedTime.TimeOfDay;
+ if (!_timeSelector.ShowSeconds)
+ {
+ selectedTime = new DateTime(
+ selectedTime.Year,
+ selectedTime.Month,
+ selectedTime.Day,
+ selectedTime.Hour,
+ selectedTime.Minute,
+ 0,
+ selectedTime.Kind);
+ }
+ SetCurrentValue(SelectedTimeProperty, selectedTime);
+ if (_textBox != null)
+ {
+ _textBox.TextChanged -= TextBox_TextChanged;
+ _textBox.Text = selectedTime.ToString(GetDisplayTimeFormat(SelectedTimeFormat));
+ _textBox.TextChanged += TextBox_TextChanged;
+ }
+ }
+ SetCurrentValue(IsDropDownOpenProperty, false);
+ }
+
+ private void OnButtonCancel_Click(object sender, RoutedEventArgs e)
+ {
+ SetCurrentValue(IsDropDownOpenProperty, false);
}
private void OnWindowPreviewMouseDown(object sender, MouseButtonEventArgs e)
{
- if (!IsMouseOver)
- IsDropDownOpen = false;
+ if (!IsMouseOver && (_popup == null || !_popup.IsMouseOver))
+ SetCurrentValue(IsDropDownOpenProperty, false);
}
private void OnTimeSelector_SelectedTimeChanged(object sender, RoutedPropertyChangedEventArgs e)
{
+ if (_buttonConfirm != null || _isSelectingTime)
+ return;
if (_textBox != null && e.NewValue != null)
{
- _textBox.Text = e.NewValue.Value.ToString(SelectedTimeFormat);
+ _textBox.Text = e.NewValue.Value.ToString(GetDisplayTimeFormat(SelectedTimeFormat));
SelectedTime = e.NewValue;
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/WPFDevelopers.Shared/Controls/TimePicker/TimeSelector.cs b/src/WPFDevelopers.Shared/Controls/TimePicker/TimeSelector.cs
index 1dc26a82..d16ddaf1 100644
--- a/src/WPFDevelopers.Shared/Controls/TimePicker/TimeSelector.cs
+++ b/src/WPFDevelopers.Shared/Controls/TimePicker/TimeSelector.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.Windows;
using System.Windows.Controls;
@@ -8,11 +9,15 @@ namespace WPFDevelopers.Controls
[TemplatePart(Name = ListBoxHourTemplateName, Type = typeof(ListBox))]
[TemplatePart(Name = ListBoxMinuteTemplateName, Type = typeof(ListBox))]
[TemplatePart(Name = ListBoxSecondTemplateName, Type = typeof(ListBox))]
+ [TemplatePart(Name = ListBoxPeriodTemplateName, Type = typeof(ListBox))]
+ [TemplatePart(Name = SecondColumnTemplateName, Type = typeof(ColumnDefinition))]
public class TimeSelector : Control
{
private const string ListBoxHourTemplateName = "PART_ListBoxHour";
private const string ListBoxMinuteTemplateName = "PART_ListBoxMinute";
private const string ListBoxSecondTemplateName = "PART_ListBoxSecond";
+ private const string ListBoxPeriodTemplateName = "PART_ListBoxPeriod";
+ private const string SecondColumnTemplateName = "PART_SecondColumn";
private const int VisibleItemCount = 10;
private const int CenterIndex = 4;
private int _hour;
@@ -22,6 +27,8 @@ public class TimeSelector : Control
private ListBox _listBoxHour;
private ListBox _listBoxMinute;
private ListBox _listBoxSecond;
+ private ListBox _listBoxPeriod;
+ private ColumnDefinition _secondColumn;
public static readonly RoutedEvent SelectedTimeChangedEvent =
EventManager.RegisterRoutedEvent(
@@ -37,6 +44,20 @@ public class TimeSelector : Control
typeof(TimeSelector),
new PropertyMetadata(null, OnSelectedTimeChanged));
+ public static readonly DependencyProperty IsTwelveHourFormatProperty =
+ DependencyProperty.Register(
+ "IsTwelveHourFormat",
+ typeof(bool),
+ typeof(TimeSelector),
+ new PropertyMetadata(false, OnIsTwelveHourFormatChanged));
+
+ public static readonly DependencyProperty ShowSecondsProperty =
+ DependencyProperty.Register(
+ "ShowSeconds",
+ typeof(bool),
+ typeof(TimeSelector),
+ new PropertyMetadata(true, OnShowSecondsChanged));
+
public static readonly DependencyProperty ItemHeightProperty =
DependencyProperty.Register(
"ItemHeight",
@@ -65,6 +86,18 @@ public DateTime? SelectedTime
set => SetValue(SelectedTimeProperty, value);
}
+ public bool IsTwelveHourFormat
+ {
+ get => (bool)GetValue(IsTwelveHourFormatProperty);
+ set => SetValue(IsTwelveHourFormatProperty, value);
+ }
+
+ public bool ShowSeconds
+ {
+ get => (bool)GetValue(ShowSecondsProperty);
+ set => SetValue(ShowSecondsProperty, value);
+ }
+
public double ItemHeight
{
get => (double)GetValue(ItemHeightProperty);
@@ -105,6 +138,35 @@ DependencyPropertyChangedEventArgs e
}
}
+ private static void OnIsTwelveHourFormatChanged(
+ DependencyObject d,
+ DependencyPropertyChangedEventArgs e
+ )
+ {
+ if (d is TimeSelector ctrl)
+ {
+ if (ctrl._listBoxPeriod != null)
+ ctrl._listBoxPeriod.Visibility = (bool)e.NewValue ? Visibility.Visible : Visibility.Collapsed;
+ ctrl.RefreshHourItems();
+ ctrl.RefreshPeriodItems();
+ }
+ }
+
+ private static void OnShowSecondsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ if (d is TimeSelector ctrl)
+ {
+ var showSeconds = (bool)e.NewValue;
+ if (ctrl._listBoxSecond != null)
+ ctrl._listBoxSecond.Visibility = showSeconds ? Visibility.Visible : Visibility.Collapsed;
+ if (ctrl._secondColumn != null)
+ ctrl._secondColumn.Width = showSeconds ? new GridLength(1, GridUnitType.Star) : new GridLength(0);
+ if (!showSeconds)
+ ctrl._second = 0;
+ ctrl.RefreshSecondItems();
+ }
+ }
+
private void HandleSelectedTimeChanged(DateTime? oldValue, DateTime? newValue)
{
if (_isRefreshing)
@@ -115,7 +177,7 @@ private void HandleSelectedTimeChanged(DateTime? oldValue, DateTime? newValue)
_hour = newValue.Value.Hour;
_minute = newValue.Value.Minute;
- _second = newValue.Value.Second;
+ _second = ShowSeconds ? newValue.Value.Second : 0;
if (_listBoxHour != null && _listBoxMinute != null && _listBoxSecond != null)
{
@@ -130,6 +192,8 @@ public override void OnApplyTemplate()
_listBoxHour = GetTemplateChild(ListBoxHourTemplateName) as ListBox;
_listBoxMinute = GetTemplateChild(ListBoxMinuteTemplateName) as ListBox;
_listBoxSecond = GetTemplateChild(ListBoxSecondTemplateName) as ListBox;
+ _listBoxPeriod = GetTemplateChild(ListBoxPeriodTemplateName) as ListBox;
+ _secondColumn = GetTemplateChild(SecondColumnTemplateName) as ColumnDefinition;
if (_listBoxHour != null)
{
@@ -148,22 +212,32 @@ public override void OnApplyTemplate()
if (_listBoxSecond != null)
{
+ _listBoxSecond.Visibility = ShowSeconds ? Visibility.Visible : Visibility.Collapsed;
_listBoxSecond.SelectionChanged -= ListBoxSecond_SelectionChanged;
_listBoxSecond.SelectionChanged += ListBoxSecond_SelectionChanged;
}
+ if (_secondColumn != null)
+ _secondColumn.Width = ShowSeconds ? new GridLength(1, GridUnitType.Star) : new GridLength(0);
+
+ if (_listBoxPeriod != null)
+ {
+ _listBoxPeriod.Visibility = IsTwelveHourFormat ? Visibility.Visible : Visibility.Collapsed;
+ _listBoxPeriod.SelectionChanged -= ListBoxPeriod_SelectionChanged;
+ _listBoxPeriod.SelectionChanged += ListBoxPeriod_SelectionChanged;
+ }
if (SelectedTime.HasValue)
{
_hour = SelectedTime.Value.Hour;
_minute = SelectedTime.Value.Minute;
- _second = SelectedTime.Value.Second;
+ _second = ShowSeconds ? SelectedTime.Value.Second : 0;
}
else
{
var now = DateTime.Now;
_hour = now.Hour;
_minute = now.Minute;
- _second = now.Second;
+ _second = ShowSeconds ? now.Second : 0;
_isRefreshing = true;
SelectedTime = new DateTime(
@@ -192,6 +266,8 @@ private void ListBox_Loaded(object sender, RoutedEventArgs e)
ItemHeight = h;
Height = h * VisibleItemCount;
SelectorMargin = new Thickness(0, CenterIndex * h, 0, 0);
+ if (_listBoxPeriod != null)
+ _listBoxPeriod.Height = h * VisibleItemCount;
}
private double GetItemHeight(ListBox listBox)
@@ -209,7 +285,7 @@ private double GetItemHeight(ListBox listBox)
return 0;
}
-
+
private List BuildCyclicItems(int current, int maxValue)
{
var list = new List(VisibleItemCount);
@@ -226,11 +302,30 @@ private List BuildCyclicItems(int current, int maxValue)
return list;
}
+ private List BuildTwelveHourItems(int hour)
+ {
+ var list = new List(VisibleItemCount);
+ var current = hour % 12;
+ if (current == 0)
+ current = 12;
+
+ for (int i = 0; i < VisibleItemCount; i++)
+ {
+ int value = (current - 1 - CenterIndex + i) % 12;
+ if (value < 0)
+ value += 12;
+ list.Add((value + 1).ToString("D2"));
+ }
+
+ return list;
+ }
+
private void RefreshAllColumns()
{
RefreshHourItems();
RefreshMinuteItems();
RefreshSecondItems();
+ RefreshPeriodItems();
}
private void RefreshSecondItems()
@@ -250,11 +345,34 @@ private void RefreshHourItems()
return;
_listBoxHour.SelectionChanged -= ListBoxHour_SelectionChanged;
- _listBoxHour.ItemsSource = BuildCyclicItems(_hour, 24);
+ _listBoxHour.ItemsSource = IsTwelveHourFormat
+ ? BuildTwelveHourItems(_hour)
+ : BuildCyclicItems(_hour, 24);
_listBoxHour.SelectedIndex = CenterIndex;
_listBoxHour.SelectionChanged += ListBoxHour_SelectionChanged;
}
+ private void RefreshPeriodItems()
+ {
+ if (_listBoxPeriod == null || !IsTwelveHourFormat)
+ return;
+
+ var dateTimeFormat = CultureInfo.CurrentCulture.DateTimeFormat;
+ var am = string.IsNullOrEmpty(dateTimeFormat.AMDesignator) ? "AM" : dateTimeFormat.AMDesignator;
+ var pm = string.IsNullOrEmpty(dateTimeFormat.PMDesignator) ? "PM" : dateTimeFormat.PMDesignator;
+ var isPm = _hour >= 12;
+ var items = new List(VisibleItemCount);
+ for (int i = 0; i < VisibleItemCount; i++)
+ items.Add(string.Empty);
+ items[CenterIndex] = isPm ? pm : am;
+ items[CenterIndex + 1] = isPm ? am : pm;
+
+ _listBoxPeriod.SelectionChanged -= ListBoxPeriod_SelectionChanged;
+ _listBoxPeriod.ItemsSource = items;
+ _listBoxPeriod.SelectedIndex = CenterIndex;
+ _listBoxPeriod.SelectionChanged += ListBoxPeriod_SelectionChanged;
+ }
+
private void RefreshMinuteItems()
{
if (_listBoxMinute == null)
@@ -309,11 +427,32 @@ private void ListBoxHour_SelectionChanged(object sender, SelectionChangedEventAr
if (!int.TryParse(_listBoxHour.SelectedItem.ToString(), out var value))
return;
+ if (IsTwelveHourFormat)
+ {
+ value %= 12;
+ if (_hour >= 12)
+ value += 12;
+ }
_hour = value;
UpdateSelectedTimeFromFields();
RefreshHourItems();
}
+ private void ListBoxPeriod_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ if (_isRefreshing || _listBoxPeriod == null || _listBoxPeriod.SelectedIndex < 0)
+ return;
+
+ var periodIsPm = _hour >= 12 ^ ((_listBoxPeriod.SelectedIndex - CenterIndex) % 2 != 0);
+ var hour = (_hour % 12) + (periodIsPm ? 12 : 0);
+ if (hour != _hour)
+ {
+ _hour = hour;
+ UpdateSelectedTimeFromFields();
+ }
+ RefreshPeriodItems();
+ }
+
private void UpdateSelectedTimeFromFields()
{
_isRefreshing = true;
@@ -337,8 +476,8 @@ public void SetTime()
_hour = SelectedTime.Value.Hour;
_minute = SelectedTime.Value.Minute;
- _second = SelectedTime.Value.Second;
+ _second = ShowSeconds ? SelectedTime.Value.Second : 0;
RefreshAllColumns();
}
}
-}
\ No newline at end of file
+}
diff --git a/src/WPFDevelopers.Shared/Controls/TimePicker/TimeSelectorListBox.cs b/src/WPFDevelopers.Shared/Controls/TimePicker/TimeSelectorListBox.cs
index 0de0fd37..d13f7e86 100644
--- a/src/WPFDevelopers.Shared/Controls/TimePicker/TimeSelectorListBox.cs
+++ b/src/WPFDevelopers.Shared/Controls/TimePicker/TimeSelectorListBox.cs
@@ -49,6 +49,11 @@ private void ScrollListBox_PreviewMouseWheel(object sender, MouseWheelEventArgs
{
if (Items == null || Items.Count == 0)
return;
+ if (Items.Count <= CenterIndex)
+ {
+ e.Handled = true;
+ return;
+ }
int step = e.Delta > 0 ? -1 : 1;
MoveSelection(step);
e.Handled = true;
@@ -111,4 +116,4 @@ protected override void OnSelectionChanged(SelectionChangedEventArgs e)
ScrollSelectedItemToCenter();
}
}
-}
\ No newline at end of file
+}
diff --git a/src/WPFDevelopers.Shared/Controls/Timeline/Timeline.cs b/src/WPFDevelopers.Shared/Controls/Timeline/Timeline.cs
new file mode 100644
index 00000000..8220cdb2
--- /dev/null
+++ b/src/WPFDevelopers.Shared/Controls/Timeline/Timeline.cs
@@ -0,0 +1,159 @@
+using System;
+using System.Collections.Specialized;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Input;
+using System.Windows.Media;
+
+namespace WPFDevelopers.Controls
+{
+ public enum TimelineMode
+ {
+ Start,
+ Alternate,
+ End
+ }
+
+ public enum TimelineItemPosition
+ {
+ Auto,
+ Start,
+ End
+ }
+
+ [TemplatePart(Name = ScrollViewerPartName, Type = typeof(ScrollViewer))]
+ public class Timeline : ItemsControl
+ {
+ private const string ScrollViewerPartName = "PART_ScrollViewer";
+ private ScrollViewer _scrollViewer;
+
+ public static readonly DependencyProperty OrientationProperty =
+ DependencyProperty.Register("Orientation", typeof(Orientation), typeof(Timeline),
+ new FrameworkPropertyMetadata(Orientation.Vertical, OnLayoutChanged),
+ value => (Orientation)value == Orientation.Vertical || (Orientation)value == Orientation.Horizontal);
+
+ public static readonly DependencyProperty ModeProperty =
+ DependencyProperty.Register("Mode", typeof(TimelineMode), typeof(Timeline),
+ new FrameworkPropertyMetadata(TimelineMode.Start, OnLayoutChanged),
+ value => Enum.IsDefined(typeof(TimelineMode), value));
+
+ public static readonly DependencyProperty ReverseProperty =
+ DependencyProperty.Register("Reverse", typeof(bool), typeof(Timeline),
+ new FrameworkPropertyMetadata(false, OnLayoutChanged));
+
+ public static readonly DependencyProperty ItemSpacingProperty =
+ DependencyProperty.Register("ItemSpacing", typeof(double), typeof(Timeline),
+ new FrameworkPropertyMetadata(20.0, OnLayoutChanged), IsValidLength);
+
+ public static readonly DependencyProperty LineBrushProperty =
+ DependencyProperty.Register("LineBrush", typeof(Brush), typeof(Timeline),
+ new FrameworkPropertyMetadata(null, OnLayoutChanged));
+
+ public static readonly DependencyProperty LineThicknessProperty =
+ DependencyProperty.Register("LineThickness", typeof(double), typeof(Timeline),
+ new FrameworkPropertyMetadata(2.0, OnLayoutChanged), IsValidLength);
+
+ static Timeline()
+ {
+ DefaultStyleKeyProperty.OverrideMetadata(typeof(Timeline), new FrameworkPropertyMetadata(typeof(Timeline)));
+ }
+
+ public Orientation Orientation
+ {
+ get { return (Orientation)GetValue(OrientationProperty); }
+ set { SetValue(OrientationProperty, value); }
+ }
+
+ public TimelineMode Mode
+ {
+ get { return (TimelineMode)GetValue(ModeProperty); }
+ set { SetValue(ModeProperty, value); }
+ }
+
+ public bool Reverse
+ {
+ get { return (bool)GetValue(ReverseProperty); }
+ set { SetValue(ReverseProperty, value); }
+ }
+
+ public double ItemSpacing
+ {
+ get { return (double)GetValue(ItemSpacingProperty); }
+ set { SetValue(ItemSpacingProperty, value); }
+ }
+
+ public Brush LineBrush
+ {
+ get { return (Brush)GetValue(LineBrushProperty); }
+ set { SetValue(LineBrushProperty, value); }
+ }
+
+ public double LineThickness
+ {
+ get { return (double)GetValue(LineThicknessProperty); }
+ set { SetValue(LineThicknessProperty, value); }
+ }
+
+ internal TimelinePanel ItemsHost { get; set; }
+
+ public override void OnApplyTemplate()
+ {
+ if (_scrollViewer != null)
+ _scrollViewer.PreviewMouseWheel -= OnScrollViewerPreviewMouseWheel;
+ base.OnApplyTemplate();
+ _scrollViewer = GetTemplateChild(ScrollViewerPartName) as ScrollViewer;
+ if (_scrollViewer != null)
+ _scrollViewer.PreviewMouseWheel += OnScrollViewerPreviewMouseWheel;
+ }
+
+ private void OnScrollViewerPreviewMouseWheel(object sender, MouseWheelEventArgs e)
+ {
+ if (e.Handled || e.Delta == 0) return;
+ var canScroll = _scrollViewer.VerticalScrollBarVisibility != ScrollBarVisibility.Disabled &&
+ (e.Delta > 0 ? _scrollViewer.VerticalOffset > 0 :
+ _scrollViewer.VerticalOffset < _scrollViewer.ScrollableHeight);
+ if (canScroll) return;
+
+ e.Handled = true;
+ RaiseEvent(new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta)
+ {
+ RoutedEvent = MouseWheelEvent,
+ Source = this
+ });
+ }
+
+ internal static bool IsValidLength(object value)
+ {
+ var length = (double)value;
+ return length >= 0 && !double.IsNaN(length) && !double.IsInfinity(length);
+ }
+
+ internal void InvalidateTimeline()
+ {
+ if (ItemsHost == null) return;
+ ItemsHost.InvalidateMeasure();
+ ItemsHost.InvalidateVisual();
+ }
+
+ protected override bool IsItemItsOwnContainerOverride(object item)
+ {
+ return item is TimelineItem;
+ }
+
+ protected override DependencyObject GetContainerForItemOverride()
+ {
+ return new TimelineItem();
+ }
+
+ protected override void OnItemsChanged(NotifyCollectionChangedEventArgs e)
+ {
+ base.OnItemsChanged(e);
+ InvalidateTimeline();
+ }
+
+ private static void OnLayoutChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ ((Timeline)d).InvalidateTimeline();
+ }
+ }
+}
diff --git a/src/WPFDevelopers.Shared/Controls/Timeline/TimelineItem.cs b/src/WPFDevelopers.Shared/Controls/Timeline/TimelineItem.cs
new file mode 100644
index 00000000..cd70c717
--- /dev/null
+++ b/src/WPFDevelopers.Shared/Controls/Timeline/TimelineItem.cs
@@ -0,0 +1,124 @@
+using System;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Media;
+
+namespace WPFDevelopers.Controls
+{
+ [TemplatePart(Name = LayoutPartName, Type = typeof(TimelineItemPanel))]
+ public class TimelineItem : ContentControl
+ {
+ private const string LayoutPartName = "PART_Layout";
+
+ private static readonly DependencyPropertyKey OrientationPropertyKey =
+ DependencyProperty.RegisterReadOnly("Orientation", typeof(Orientation), typeof(TimelineItem),
+ new FrameworkPropertyMetadata(Orientation.Vertical, FrameworkPropertyMetadataOptions.AffectsMeasure));
+
+ private static readonly DependencyPropertyKey ActualPositionPropertyKey =
+ DependencyProperty.RegisterReadOnly("ActualPosition", typeof(TimelineItemPosition), typeof(TimelineItem),
+ new FrameworkPropertyMetadata(TimelineItemPosition.Start, FrameworkPropertyMetadataOptions.AffectsMeasure));
+
+ public static readonly DependencyProperty OrientationProperty = OrientationPropertyKey.DependencyProperty;
+ public static readonly DependencyProperty ActualPositionProperty = ActualPositionPropertyKey.DependencyProperty;
+
+ public static readonly DependencyProperty LabelProperty = Register("Label", typeof(object), null);
+ public static readonly DependencyProperty LabelTemplateProperty = Register("LabelTemplate", typeof(DataTemplate), null);
+ public static readonly DependencyProperty DotProperty = Register("Dot", typeof(object), null);
+ public static readonly DependencyProperty DotTemplateProperty = Register("DotTemplate", typeof(DataTemplate), null);
+ public static readonly DependencyProperty DotBrushProperty = Register("DotBrush", typeof(Brush), null);
+ public static readonly DependencyProperty IsLoadingProperty = Register("IsLoading", typeof(bool), false);
+
+ public static readonly DependencyProperty PositionProperty =
+ DependencyProperty.Register("Position", typeof(TimelineItemPosition), typeof(TimelineItem),
+ new FrameworkPropertyMetadata(TimelineItemPosition.Auto,
+ FrameworkPropertyMetadataOptions.AffectsMeasure, OnLayoutChanged),
+ value => Enum.IsDefined(typeof(TimelineItemPosition), value));
+
+ static TimelineItem()
+ {
+ DefaultStyleKeyProperty.OverrideMetadata(typeof(TimelineItem), new FrameworkPropertyMetadata(typeof(TimelineItem)));
+ HorizontalContentAlignmentProperty.OverrideMetadata(typeof(TimelineItem),
+ new FrameworkPropertyMetadata(HorizontalAlignment.Stretch));
+ }
+
+ public object Label
+ {
+ get { return GetValue(LabelProperty); }
+ set { SetValue(LabelProperty, value); }
+ }
+
+ public DataTemplate LabelTemplate
+ {
+ get { return (DataTemplate)GetValue(LabelTemplateProperty); }
+ set { SetValue(LabelTemplateProperty, value); }
+ }
+
+ public object Dot
+ {
+ get { return GetValue(DotProperty); }
+ set { SetValue(DotProperty, value); }
+ }
+
+ public DataTemplate DotTemplate
+ {
+ get { return (DataTemplate)GetValue(DotTemplateProperty); }
+ set { SetValue(DotTemplateProperty, value); }
+ }
+
+ public Brush DotBrush
+ {
+ get { return (Brush)GetValue(DotBrushProperty); }
+ set { SetValue(DotBrushProperty, value); }
+ }
+
+ public bool IsLoading
+ {
+ get { return (bool)GetValue(IsLoadingProperty); }
+ set { SetValue(IsLoadingProperty, value); }
+ }
+
+ public TimelineItemPosition Position
+ {
+ get { return (TimelineItemPosition)GetValue(PositionProperty); }
+ set { SetValue(PositionProperty, value); }
+ }
+
+ public Orientation Orientation
+ {
+ get { return (Orientation)GetValue(OrientationProperty); }
+ }
+
+ public TimelineItemPosition ActualPosition
+ {
+ get { return (TimelineItemPosition)GetValue(ActualPositionProperty); }
+ }
+
+ internal TimelineItemPanel LayoutPanel { get; private set; }
+
+ public override void OnApplyTemplate()
+ {
+ base.OnApplyTemplate();
+ LayoutPanel = GetTemplateChild(LayoutPartName) as TimelineItemPanel;
+ }
+
+ internal void UpdateLayout(Orientation orientation, TimelineItemPosition position)
+ {
+ if (Orientation == orientation && ActualPosition == position) return;
+ SetValue(OrientationPropertyKey, orientation);
+ SetValue(ActualPositionPropertyKey, position);
+ if (LayoutPanel != null) LayoutPanel.InvalidateMeasure();
+ }
+
+ private static DependencyProperty Register(string name, Type type, object defaultValue)
+ {
+ return DependencyProperty.Register(name, type, typeof(TimelineItem),
+ new FrameworkPropertyMetadata(defaultValue, FrameworkPropertyMetadataOptions.AffectsMeasure, OnLayoutChanged));
+ }
+
+ private static void OnLayoutChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ var owner = ItemsControl.ItemsControlFromItemContainer((TimelineItem)d) as Timeline;
+ if (owner != null) owner.InvalidateTimeline();
+ }
+ }
+}
diff --git a/src/WPFDevelopers.Shared/Controls/Timeline/TimelineItemPanel.cs b/src/WPFDevelopers.Shared/Controls/Timeline/TimelineItemPanel.cs
new file mode 100644
index 00000000..a495997c
--- /dev/null
+++ b/src/WPFDevelopers.Shared/Controls/Timeline/TimelineItemPanel.cs
@@ -0,0 +1,93 @@
+using System;
+using System.Windows;
+using System.Windows.Controls;
+
+namespace WPFDevelopers.Controls
+{
+ public class TimelineItemPanel : Panel
+ {
+ private const double ContentGap = 12;
+ private bool _splitCrossAxis;
+
+ internal bool SplitCrossAxis
+ {
+ get { return _splitCrossAxis; }
+ set
+ {
+ if (_splitCrossAxis == value) return;
+ _splitCrossAxis = value;
+ InvalidateMeasure();
+ }
+ }
+
+ internal double AxisOffset { get; set; }
+ internal double Before { get; private set; }
+ internal double After { get; private set; }
+ internal Point DotCenter { get; private set; }
+ internal Size DotSize { get; private set; }
+
+ protected override Size MeasureOverride(Size availableSize)
+ {
+ var item = TemplatedParent as TimelineItem;
+ if (item == null || InternalChildren.Count != 3) return new Size();
+ var vertical = item.Orientation == Orientation.Vertical;
+ var label = InternalChildren[0];
+ var dot = InternalChildren[1];
+ var content = InternalChildren[2];
+ dot.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
+ DotSize = dot.DesiredSize;
+ var cross = vertical ? availableSize.Width : availableSize.Height;
+ var halfDot = (vertical ? DotSize.Width : DotSize.Height) / 2;
+ var budget = Math.Max(0, (SplitCrossAxis ? cross / 2 : cross - halfDot) - halfDot - ContentGap);
+ var constraint = vertical
+ ? new Size(budget, double.PositiveInfinity)
+ : new Size(availableSize.Width, budget);
+ label.Measure(constraint);
+ content.Measure(constraint);
+ var labelCross = vertical ? label.DesiredSize.Width : label.DesiredSize.Height;
+ var contentCross = vertical ? content.DesiredSize.Width : content.DesiredSize.Height;
+ var leading = item.ActualPosition == TimelineItemPosition.Start ? labelCross : contentCross;
+ var trailing = item.ActualPosition == TimelineItemPosition.Start ? contentCross : labelCross;
+ Before = halfDot + (leading > 0 ? leading + ContentGap : 0);
+ After = halfDot + (trailing > 0 ? trailing + ContentGap : 0);
+ var length = vertical
+ ? Math.Max(DotSize.Height, Math.Max(label.DesiredSize.Height, content.DesiredSize.Height))
+ : Math.Max(DotSize.Width, Math.Max(label.DesiredSize.Width, content.DesiredSize.Width));
+ return vertical ? new Size(Before + After, length) : new Size(length, Before + After);
+ }
+
+ protected override Size ArrangeOverride(Size finalSize)
+ {
+ var item = TemplatedParent as TimelineItem;
+ if (item == null || InternalChildren.Count != 3) return finalSize;
+ var vertical = item.Orientation == Orientation.Vertical;
+ var halfDot = (vertical ? DotSize.Width : DotSize.Height) / 2;
+ DotCenter = vertical ? new Point(AxisOffset, DotSize.Height / 2) : new Point(DotSize.Width / 2, AxisOffset);
+ InternalChildren[1].Arrange(new Rect(
+ DotCenter.X - DotSize.Width / 2, DotCenter.Y - DotSize.Height / 2, DotSize.Width, DotSize.Height));
+ var before = Math.Max(0, AxisOffset - halfDot - ContentGap);
+ var afterStart = AxisOffset + halfDot + ContentGap;
+ var after = Math.Max(0, (vertical ? finalSize.Width : finalSize.Height) - afterStart);
+ var start = item.ActualPosition == TimelineItemPosition.Start;
+ ArrangeContent(InternalChildren[0], vertical, !start, before, afterStart, after, finalSize);
+ ArrangeContent(InternalChildren[2], vertical, start, before, afterStart, after, finalSize);
+ return finalSize;
+ }
+
+ private static void ArrangeContent(UIElement child, bool vertical, bool afterAxis,
+ double before, double afterStart, double after, Size finalSize)
+ {
+ if (vertical)
+ {
+ var width = afterAxis ? after : before;
+ child.Arrange(new Rect(afterAxis ? afterStart : Math.Max(0, before - child.DesiredSize.Width),
+ 0, Math.Min(width, child.DesiredSize.Width), finalSize.Height));
+ }
+ else
+ {
+ child.Arrange(new Rect(0, afterAxis ? afterStart : Math.Max(0, before - child.DesiredSize.Height),
+ finalSize.Width, Math.Min(afterAxis ? after : before, child.DesiredSize.Height)));
+ }
+ }
+ }
+}
diff --git a/src/WPFDevelopers.Shared/Controls/Timeline/TimelinePanel.cs b/src/WPFDevelopers.Shared/Controls/Timeline/TimelinePanel.cs
new file mode 100644
index 00000000..7b622313
--- /dev/null
+++ b/src/WPFDevelopers.Shared/Controls/Timeline/TimelinePanel.cs
@@ -0,0 +1,131 @@
+using System;
+using System.Collections.Generic;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Media;
+
+namespace WPFDevelopers.Controls
+{
+ public class TimelinePanel : Panel
+ {
+ private readonly List _items = new List();
+ private Timeline _owner;
+ private double _before;
+ private double _after;
+ private bool _splitCrossAxis;
+
+ protected override Size MeasureOverride(Size availableSize)
+ {
+ _owner = ItemsControl.GetItemsOwner(this) as Timeline;
+ _items.Clear();
+ if (_owner == null) return new Size();
+ _owner.ItemsHost = this;
+ foreach (UIElement child in InternalChildren)
+ {
+ var item = child as TimelineItem;
+ if (item != null && item.Visibility != Visibility.Collapsed) _items.Add(item);
+ }
+ if (_owner.Reverse) _items.Reverse();
+
+ var hasStart = false;
+ var hasEnd = false;
+ for (var i = 0; i < _items.Count; i++)
+ {
+ var item = _items[i];
+ var position = item.Position;
+ if (position == TimelineItemPosition.Auto)
+ position = _owner.Mode == TimelineMode.End ||
+ (_owner.Mode == TimelineMode.Alternate && i % 2 != 0)
+ ? TimelineItemPosition.End : TimelineItemPosition.Start;
+ item.UpdateLayout(_owner.Orientation, position);
+ hasStart |= position == TimelineItemPosition.Start || item.Label != null || item.LabelTemplate != null;
+ hasEnd |= position == TimelineItemPosition.End || item.Label != null || item.LabelTemplate != null;
+ }
+ _splitCrossAxis = hasStart && hasEnd;
+ _before = 0;
+ _after = 0;
+ var vertical = _owner.Orientation == Orientation.Vertical;
+ var length = 0.0;
+ var constraint = vertical ? new Size(availableSize.Width, double.PositiveInfinity) : availableSize;
+ if (!vertical && _items.Count > 0 && !double.IsInfinity(availableSize.Width))
+ constraint.Width = Math.Max(0, (availableSize.Width - _owner.ItemSpacing * (_items.Count - 1)) / _items.Count);
+ foreach (var item in _items)
+ {
+ item.ApplyTemplate();
+ var layout = item.LayoutPanel;
+ if (layout != null) layout.SplitCrossAxis = _splitCrossAxis;
+ item.Measure(constraint);
+ if (layout != null)
+ {
+ _before = Math.Max(_before, layout.Before);
+ _after = Math.Max(_after, layout.After);
+ }
+ length += vertical ? item.DesiredSize.Height : item.DesiredSize.Width;
+ }
+ length += Math.Max(0, _items.Count - 1) * _owner.ItemSpacing;
+ var cross = _splitCrossAxis ? 2 * Math.Max(_before, _after) : _before + _after;
+ return vertical ? new Size(cross, length) : new Size(length, cross);
+ }
+
+ protected override Size ArrangeOverride(Size finalSize)
+ {
+ if (_owner == null) return finalSize;
+ var vertical = _owner.Orientation == Orientation.Vertical;
+ var cross = vertical ? finalSize.Width : finalSize.Height;
+ var axis = _splitCrossAxis ? cross / 2 : (_before > _after ? cross - _after : _before);
+ var desiredLength = 0.0;
+ foreach (var item in _items)
+ desiredLength += vertical ? item.DesiredSize.Height : item.DesiredSize.Width;
+ desiredLength += Math.Max(0, _items.Count - 1) * _owner.ItemSpacing;
+ var extra = !vertical && _items.Count > 0 ? Math.Max(0, finalSize.Width - desiredLength) / _items.Count : 0;
+ var offset = 0.0;
+ foreach (var item in _items)
+ {
+ if (item.LayoutPanel != null)
+ {
+ item.LayoutPanel.AxisOffset = axis;
+ item.LayoutPanel.InvalidateArrange();
+ }
+ var length = (vertical ? item.DesiredSize.Height : item.DesiredSize.Width) + extra;
+ item.Arrange(vertical ? new Rect(0, offset, finalSize.Width, length)
+ : new Rect(offset, 0, length, finalSize.Height));
+ offset += length + _owner.ItemSpacing;
+ }
+ InvalidateVisual();
+ return finalSize;
+ }
+
+ protected override void OnRender(DrawingContext drawingContext)
+ {
+ base.OnRender(drawingContext);
+ if (_owner == null || _owner.LineBrush == null || _owner.LineThickness <= 0) return;
+ var vertical = _owner.Orientation == Orientation.Vertical;
+ for (var i = 1; i < _items.Count; i++)
+ {
+ var previous = _items[i - 1];
+ var current = _items[i];
+ if (previous.LayoutPanel == null || current.LayoutPanel == null ||
+ previous.Visibility != Visibility.Visible || current.Visibility != Visibility.Visible) continue;
+ var start = previous.LayoutPanel.TranslatePoint(previous.LayoutPanel.DotCenter, this);
+ var end = current.LayoutPanel.TranslatePoint(current.LayoutPanel.DotCenter, this);
+ var startGap = (vertical ? previous.LayoutPanel.DotSize.Height : previous.LayoutPanel.DotSize.Width) / 2 + 2;
+ var endGap = (vertical ? current.LayoutPanel.DotSize.Height : current.LayoutPanel.DotSize.Width) / 2 + 2;
+ if (vertical)
+ {
+ start.Y += startGap;
+ end.Y -= endGap;
+ if (end.Y <= start.Y) continue;
+ }
+ else
+ {
+ start.X += startGap;
+ end.X -= endGap;
+ if (end.X <= start.X) continue;
+ }
+ var pen = new Pen(_owner.LineBrush, _owner.LineThickness);
+ if (current.IsLoading || previous.IsLoading) pen.DashStyle = DashStyles.Dash;
+ drawingContext.DrawLine(pen, start, end);
+ }
+ }
+ }
+}
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;
}
diff --git a/src/WPFDevelopers.Shared/Controls/WaterfallPanel/WaterfallItemsControl.cs b/src/WPFDevelopers.Shared/Controls/WaterfallPanel/WaterfallItemsControl.cs
new file mode 100644
index 00000000..10ad16a9
--- /dev/null
+++ b/src/WPFDevelopers.Shared/Controls/WaterfallPanel/WaterfallItemsControl.cs
@@ -0,0 +1,65 @@
+using System.Windows;
+using System.Windows.Controls;
+
+namespace WPFDevelopers.Controls
+{
+ ///
+ /// An items control with responsive masonry layout and a virtualizing scrolling template.
+ /// Give the control a finite height to enable viewport-based container realization.
+ ///
+ public class WaterfallItemsControl : ItemsControl
+ {
+ public static readonly DependencyProperty ColumnsProperty =
+ DependencyProperty.Register("Columns", typeof(int), typeof(WaterfallItemsControl),
+ new FrameworkPropertyMetadata(3), value => (int)value > 0);
+
+ public static readonly DependencyProperty MinColumnWidthProperty =
+ DependencyProperty.Register("MinColumnWidth", typeof(double), typeof(WaterfallItemsControl),
+ new FrameworkPropertyMetadata(0.0), IsFiniteNonNegative);
+
+ public static readonly DependencyProperty SpacingProperty =
+ DependencyProperty.Register("Spacing", typeof(double), typeof(WaterfallItemsControl),
+ new FrameworkPropertyMetadata(5.0), IsFiniteNonNegative);
+
+ public static readonly DependencyProperty EstimatedItemHeightProperty =
+ DependencyProperty.Register("EstimatedItemHeight", typeof(double), typeof(WaterfallItemsControl),
+ new FrameworkPropertyMetadata(200.0),
+ value => (double)value > 0 && !double.IsInfinity((double)value));
+
+ private static bool IsFiniteNonNegative(object value)
+ {
+ var number = (double)value;
+ return number >= 0 && !double.IsInfinity(number);
+ }
+
+ static WaterfallItemsControl()
+ {
+ DefaultStyleKeyProperty.OverrideMetadata(typeof(WaterfallItemsControl),
+ new FrameworkPropertyMetadata(typeof(WaterfallItemsControl)));
+ }
+
+ public int Columns
+ {
+ get { return (int)GetValue(ColumnsProperty); }
+ set { SetValue(ColumnsProperty, value); }
+ }
+
+ public double MinColumnWidth
+ {
+ get { return (double)GetValue(MinColumnWidthProperty); }
+ set { SetValue(MinColumnWidthProperty, value); }
+ }
+
+ public double Spacing
+ {
+ get { return (double)GetValue(SpacingProperty); }
+ set { SetValue(SpacingProperty, value); }
+ }
+
+ public double EstimatedItemHeight
+ {
+ get { return (double)GetValue(EstimatedItemHeightProperty); }
+ set { SetValue(EstimatedItemHeightProperty, value); }
+ }
+ }
+}
diff --git a/src/WPFDevelopers.Shared/Controls/WaterfallPanel/WaterfallPanel.Virtualization.cs b/src/WPFDevelopers.Shared/Controls/WaterfallPanel/WaterfallPanel.Virtualization.cs
new file mode 100644
index 00000000..a33fed79
--- /dev/null
+++ b/src/WPFDevelopers.Shared/Controls/WaterfallPanel/WaterfallPanel.Virtualization.cs
@@ -0,0 +1,663 @@
+using System;
+using System.Collections.Generic;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Controls.Primitives;
+using System.Windows.Media;
+using System.Windows.Threading;
+
+namespace WPFDevelopers.Controls
+{
+ public partial class WaterfallPanel : IScrollInfo
+ {
+ private const double ScrollLineAmount = 16.0;
+ private const int MaximumCorrectionPasses = 3;
+
+ private readonly List _itemHeights = new List();
+ private readonly List _collapsedItems = new List();
+ private readonly List _itemLayouts = new List();
+ private readonly List _realizationIndices = new List();
+ private ItemsControl _itemsControl;
+ private double _layoutWidth = double.NaN;
+ private int _layoutColumns;
+ private bool _hasLayout;
+ private bool _layoutsDirty = true;
+ private List[] _columnItems = new List[0];
+ private bool _hasExtent;
+ private bool _correctionQueued;
+ private int _bringIntoViewIndex = -1;
+ private double[] _columnHeights = new double[0];
+ private bool[] _columnHasItems = new bool[0];
+
+ private static readonly DependencyPropertyKey ActualColumnsPropertyKey =
+ DependencyProperty.RegisterReadOnly(
+ "ActualColumns",
+ typeof(int),
+ typeof(WaterfallPanel),
+ new FrameworkPropertyMetadata(3));
+
+ /// Read-only number of columns selected for the current panel width.
+ public static readonly DependencyProperty ActualColumnsProperty = ActualColumnsPropertyKey.DependencyProperty;
+
+ public int ActualColumns
+ {
+ get { return (int)GetValue(ActualColumnsProperty); }
+ }
+
+ public static readonly DependencyProperty EstimatedItemHeightProperty =
+ DependencyProperty.Register(
+ "EstimatedItemHeight",
+ typeof(double),
+ typeof(WaterfallPanel),
+ new FrameworkPropertyMetadata(200.0, OnEstimateChanged),
+ IsFinitePositive);
+
+ ///
+ /// Gets or sets the positive finite height used to position items before they are measured.
+ /// Better estimates reduce position corrections when scrolling to distant items.
+ ///
+ public double EstimatedItemHeight
+ {
+ get { return (double)GetValue(EstimatedItemHeightProperty); }
+ set { SetValue(EstimatedItemHeightProperty, value); }
+ }
+
+ private Size _extentSize;
+ private Size _viewportSize;
+ private Point _scrollOffset;
+ private ScrollViewer _scrollOwner;
+
+ private static bool IsFinitePositive(object value)
+ {
+ double number = (double)value;
+ return !double.IsNaN(number) && !double.IsInfinity(number) && number > 0;
+ }
+
+ private static void OnLayoutPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
+ {
+ var panel = (WaterfallPanel)dependencyObject;
+ panel._hasLayout = false;
+ panel.InvalidateMeasure();
+ }
+
+ private static void OnEstimateChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
+ {
+ WaterfallPanel panel = (WaterfallPanel)dependencyObject;
+ panel.ResetItemMeasurements();
+ panel.InvalidateMeasure();
+ }
+
+ protected override void OnInitialized(EventArgs e)
+ {
+ base.OnInitialized(e);
+ _itemsControl = ItemsControl.GetItemsOwner(this);
+ }
+
+ protected override void OnItemsChanged(object sender, ItemsChangedEventArgs args)
+ {
+ base.OnItemsChanged(sender, args);
+
+ RemoveAllRealizedChildren();
+ ResetItemMeasurements();
+ _bringIntoViewIndex = -1;
+ InvalidateMeasure();
+ }
+
+ private void RemoveAllRealizedChildren()
+ {
+ IItemContainerGenerator generator = ItemContainerGenerator;
+ for (int visualIndex = Children.Count - 1; visualIndex >= 0; visualIndex--)
+ {
+ UIElement child = Children[visualIndex];
+ int itemIndex = _itemsControl == null ? -1 : _itemsControl.ItemContainerGenerator.IndexFromContainer(child);
+ if (itemIndex >= 0)
+ {
+ GeneratorPosition position = generator.GeneratorPositionFromIndex(itemIndex);
+ if (position.Index >= 0)
+ {
+ if (ShouldRecycle() && !(_itemsControl.Items[itemIndex] is UIElement) &&
+ generator is IRecyclingItemContainerGenerator)
+ ((IRecyclingItemContainerGenerator)generator).Recycle(position, 1);
+ else
+ generator.Remove(position, 1);
+ }
+ }
+
+ RemoveInternalChildRange(visualIndex, 1);
+ }
+ }
+
+ private bool ShouldRecycle()
+ {
+ return _itemsControl != null &&
+ VirtualizingStackPanel.GetVirtualizationMode(_itemsControl) == VirtualizationMode.Recycling;
+ }
+
+ private void ResetItemMeasurements()
+ {
+ _itemHeights.Clear();
+ _collapsedItems.Clear();
+ _itemLayouts.Clear();
+ _layoutsDirty = true;
+ _hasLayout = false;
+ }
+
+ private Size MeasureVirtualized(Size availableSize)
+ {
+ if (double.IsInfinity(availableSize.Width) || double.IsInfinity(availableSize.Height))
+ throw new InvalidOperationException("Virtualized waterfall layout requires a finite viewport width and height.");
+
+ if (_itemsControl == null)
+ _itemsControl = ItemsControl.GetItemsOwner(this);
+ if (_itemsControl == null)
+ return availableSize;
+
+ int itemCount = _itemsControl.Items.Count;
+ EnsureItemState(itemCount);
+
+ double width = Math.Max(0, availableSize.Width);
+ double viewportHeight = Math.Max(0, availableSize.Height);
+ int columns = WaterfallPanel.ResolveColumns(width, Columns, MinColumnWidth, Spacing);
+ if (columns < 1)
+ columns = 1;
+
+ bool widthChanged = !_hasLayout || width != _layoutWidth || columns != _layoutColumns;
+ if (widthChanged)
+ ResetItemMeasurementsForCount(itemCount);
+
+ _layoutWidth = width;
+ _layoutColumns = columns;
+ _hasLayout = true;
+ SetValue(ActualColumnsPropertyKey, columns);
+
+ double columnWidth = Math.Max(0, (width - (columns - 1) * Spacing) / columns);
+ _viewportSize = new Size(width, viewportHeight);
+ bool needsCorrection = false;
+
+ for (int pass = 0; pass < MaximumCorrectionPasses; pass++)
+ {
+ BuildItemLayouts(itemCount, columns, columnWidth);
+ UpdateExtent(width, viewportHeight);
+ ClampVerticalOffset();
+ EnsurePendingItemVisible(viewportHeight);
+
+ SelectRealizationItems(itemCount, viewportHeight);
+ ReconcileRealizedChildren();
+ bool passHeightChanged = MeasureRealizedChildren(columnWidth);
+
+ if (!passHeightChanged)
+ break;
+ if (pass == MaximumCorrectionPasses - 1)
+ needsCorrection = true;
+ }
+
+ if (needsCorrection)
+ QueueCorrectionMeasure();
+
+ // Rebuild once with the latest measurements for the arrange pass.
+ BuildItemLayouts(itemCount, columns, columnWidth);
+ UpdateExtent(width, viewportHeight);
+ ClampVerticalOffset();
+ EnsurePendingItemVisible(viewportHeight);
+ SelectRealizationItems(itemCount, viewportHeight);
+ for (int index = 0; index < _realizationIndices.Count; index++)
+ {
+ int i = _realizationIndices[index];
+ var layout = _itemLayouts[i];
+ if (!layout.IsEmpty && layout.Bottom >= _scrollOffset.Y &&
+ layout.Top <= _scrollOffset.Y + viewportHeight &&
+ _itemsControl.ItemContainerGenerator.ContainerFromIndex(i) == null)
+ {
+ QueueCorrectionMeasure();
+ break;
+ }
+ }
+ _bringIntoViewIndex = -1;
+ return availableSize;
+ }
+
+ private void EnsureItemState(int itemCount)
+ {
+ while (_itemHeights.Count < itemCount)
+ {
+ _itemHeights.Add(EstimatedItemHeight);
+ _collapsedItems.Add(false);
+ }
+
+ while (_itemHeights.Count > itemCount)
+ {
+ _itemHeights.RemoveAt(_itemHeights.Count - 1);
+ _collapsedItems.RemoveAt(_collapsedItems.Count - 1);
+ }
+ }
+
+ private void ResetItemMeasurementsForCount(int itemCount)
+ {
+ _layoutsDirty = true;
+ EnsureItemState(itemCount);
+ for (int i = 0; i < itemCount; i++)
+ {
+ _itemHeights[i] = EstimatedItemHeight;
+ _collapsedItems[i] = false;
+ }
+ }
+
+ private void BuildItemLayouts(int itemCount, int columns, double columnWidth)
+ {
+ if (!_layoutsDirty && _itemLayouts.Count == itemCount)
+ return;
+ EnsureItemState(itemCount);
+ _itemLayouts.Clear();
+ if (_columnHeights.Length != columns)
+ {
+ _columnHeights = new double[columns];
+ _columnHasItems = new bool[columns];
+ _columnItems = new List[columns];
+ for (int column = 0; column < columns; column++)
+ _columnItems[column] = new List();
+ }
+ Array.Clear(_columnHeights, 0, columns);
+ Array.Clear(_columnHasItems, 0, columns);
+ for (int column = 0; column < columns; column++)
+ _columnItems[column].Clear();
+
+ for (int i = 0; i < itemCount; i++)
+ {
+ if (_collapsedItems[i])
+ {
+ _itemLayouts.Add(new Rect(0, _columnHeights[0], columnWidth, 0));
+ _columnItems[0].Add(i);
+ continue;
+ }
+
+ int shortestColumn = 0;
+ for (int column = 1; column < columns; column++)
+ {
+ if (!_columnHasItems[shortestColumn])
+ break;
+ if (!_columnHasItems[column] || _columnHeights[column] < _columnHeights[shortestColumn])
+ shortestColumn = column;
+ }
+
+ double y = _columnHeights[shortestColumn];
+ if (_columnHasItems[shortestColumn])
+ y += Spacing;
+
+ Rect layout = new Rect(shortestColumn * (columnWidth + Spacing), y, columnWidth, _itemHeights[i]);
+ _itemLayouts.Add(layout);
+ _columnItems[shortestColumn].Add(i);
+ _columnHeights[shortestColumn] = y + _itemHeights[i];
+ _columnHasItems[shortestColumn] = true;
+ }
+ _layoutsDirty = false;
+ }
+
+ private void UpdateExtent(double width, double viewportHeight)
+ {
+ double oldMaxOffset = Math.Max(0, _extentSize.Height - _viewportSize.Height);
+ bool wasAtBottom = _hasExtent && oldMaxOffset > 0 &&
+ Math.Abs(_scrollOffset.Y - oldMaxOffset) < 0.5;
+ double height = 0;
+ for (int i = 0; i < _columnHeights.Length; i++)
+ height = Math.Max(height, _columnHeights[i]);
+
+ _extentSize = new Size(width, Math.Max(viewportHeight, height));
+ if (wasAtBottom)
+ _scrollOffset.Y = Math.Max(0, _extentSize.Height - viewportHeight);
+ _hasExtent = true;
+ if (_scrollOwner != null)
+ _scrollOwner.InvalidateScrollInfo();
+ }
+
+ private void ClampVerticalOffset()
+ {
+ double maxOffset = Math.Max(0, _extentSize.Height - _viewportSize.Height);
+ _scrollOffset.Y = Math.Max(0, Math.Min(_scrollOffset.Y, maxOffset));
+ _scrollOffset.X = 0;
+ }
+
+ private void SelectRealizationItems(int itemCount, double viewportHeight)
+ {
+ _realizationIndices.Clear();
+ if (!VirtualizingStackPanel.GetIsVirtualizing(_itemsControl))
+ {
+ for (int i = 0; i < itemCount; i++)
+ _realizationIndices.Add(i);
+ return;
+ }
+
+ double cacheTop = Math.Max(0, _scrollOffset.Y - viewportHeight);
+ double cacheBottom = _scrollOffset.Y + viewportHeight * 2;
+
+ for (int column = 0; column < _columnItems.Length; column++)
+ {
+ var items = _columnItems[column];
+ int low = 0;
+ int high = items.Count;
+ while (low < high)
+ {
+ int middle = low + (high - low) / 2;
+ if (_itemLayouts[items[middle]].Bottom < cacheTop)
+ low = middle + 1;
+ else
+ high = middle;
+ }
+ for (int index = low; index < items.Count; index++)
+ {
+ int itemIndex = items[index];
+ if (_itemLayouts[itemIndex].Top > cacheBottom)
+ break;
+ _realizationIndices.Add(itemIndex);
+ }
+ }
+ _realizationIndices.Sort();
+ }
+
+ private bool IsSelected(int itemIndex)
+ {
+ int low = 0;
+ int high = _realizationIndices.Count - 1;
+ while (low <= high)
+ {
+ int middle = low + (high - low) / 2;
+ int candidate = _realizationIndices[middle];
+ if (candidate == itemIndex)
+ return true;
+ if (candidate < itemIndex)
+ low = middle + 1;
+ else
+ high = middle - 1;
+ }
+ return false;
+ }
+
+ private void ReconcileRealizedChildren()
+ {
+ IItemContainerGenerator generator = ItemContainerGenerator;
+ for (int visualIndex = Children.Count - 1; visualIndex >= 0; visualIndex--)
+ {
+ UIElement child = Children[visualIndex];
+ int itemIndex = _itemsControl.ItemContainerGenerator.IndexFromContainer(child);
+ if (itemIndex < 0)
+ itemIndex = GetVirtualItemIndex(child);
+
+ if (itemIndex < 0 || !IsSelected(itemIndex))
+ {
+ int currentIndex = _itemsControl.ItemContainerGenerator.IndexFromContainer(child);
+ if (currentIndex >= 0)
+ {
+ GeneratorPosition position = generator.GeneratorPositionFromIndex(currentIndex);
+ if (position.Index >= 0)
+ {
+ if (ShouldRecycle() && !(_itemsControl.Items[currentIndex] is UIElement) &&
+ generator is IRecyclingItemContainerGenerator)
+ ((IRecyclingItemContainerGenerator)generator).Recycle(position, 1);
+ else
+ generator.Remove(position, 1);
+ }
+ }
+ RemoveInternalChildRange(visualIndex, 1);
+ }
+ }
+
+ int visualTargetIndex = 0;
+ for (int targetIndex = 0; targetIndex < _realizationIndices.Count; targetIndex++)
+ {
+ int itemIndex = _realizationIndices[targetIndex];
+ GeneratorPosition position = generator.GeneratorPositionFromIndex(itemIndex);
+ UIElement child;
+ bool newlyRealized;
+
+ using (generator.StartAt(position, GeneratorDirection.Forward, true))
+ child = (UIElement)generator.GenerateNext(out newlyRealized);
+
+ SetVirtualItemIndex(child, itemIndex);
+ if (newlyRealized)
+ {
+ InsertInternalChild(visualTargetIndex, child);
+ }
+ else
+ {
+ int currentVisualIndex = Children.IndexOf(child);
+ if (currentVisualIndex < 0)
+ InsertInternalChild(visualTargetIndex, child);
+ else if (currentVisualIndex != visualTargetIndex)
+ {
+ RemoveInternalChildRange(currentVisualIndex, 1);
+ InsertInternalChild(visualTargetIndex, child);
+ }
+ }
+
+ if (newlyRealized)
+ generator.PrepareItemContainer(child);
+ visualTargetIndex++;
+ }
+ }
+
+ private bool MeasureRealizedChildren(double columnWidth)
+ {
+ bool changed = false;
+ for (int i = 0; i < Children.Count; i++)
+ {
+ UIElement child = Children[i];
+ int itemIndex = GetVirtualItemIndex(child);
+ if (itemIndex < 0 || itemIndex >= _itemHeights.Count)
+ continue;
+
+ child.Measure(new Size(columnWidth, double.PositiveInfinity));
+ bool collapsed = child.Visibility == Visibility.Collapsed;
+ double measuredHeight = collapsed ? 0 : child.DesiredSize.Height;
+ if (double.IsNaN(measuredHeight) || double.IsInfinity(measuredHeight) || measuredHeight < 0)
+ throw new InvalidOperationException("A waterfall item returned an invalid desired height.");
+
+ if (_collapsedItems[itemIndex] != collapsed || _itemHeights[itemIndex] != measuredHeight)
+ {
+ _collapsedItems[itemIndex] = collapsed;
+ _itemHeights[itemIndex] = measuredHeight;
+ _layoutsDirty = true;
+ changed = true;
+ }
+ }
+ return changed;
+ }
+
+ private void ArrangeRealizedChildren()
+ {
+ for (int i = 0; i < Children.Count; i++)
+ {
+ UIElement child = Children[i];
+ int itemIndex = GetVirtualItemIndex(child);
+ Rect layout = itemIndex >= 0 && itemIndex < _itemLayouts.Count
+ ? _itemLayouts[itemIndex]
+ : Rect.Empty;
+
+ if (layout.IsEmpty)
+ child.Arrange(new Rect());
+ else
+ child.Arrange(new Rect(layout.X, layout.Y - _scrollOffset.Y, layout.Width, layout.Height));
+ }
+ }
+
+ private void QueueCorrectionMeasure()
+ {
+ if (_correctionQueued)
+ return;
+
+ _correctionQueued = true;
+ Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(delegate
+ {
+ _correctionQueued = false;
+ InvalidateMeasure();
+ }));
+ }
+
+ private static readonly DependencyProperty VirtualItemIndexProperty =
+ DependencyProperty.RegisterAttached(
+ "VirtualItemIndex",
+ typeof(int),
+ typeof(WaterfallPanel),
+ new FrameworkPropertyMetadata(-1));
+
+ private static int GetVirtualItemIndex(DependencyObject element)
+ {
+ return (int)element.GetValue(VirtualItemIndexProperty);
+ }
+
+ private static void SetVirtualItemIndex(DependencyObject element, int index)
+ {
+ element.SetValue(VirtualItemIndexProperty, index);
+ }
+
+ protected override void BringIndexIntoView(int index)
+ {
+ var owner = _itemsControl ?? ItemsControl.GetItemsOwner(this);
+ if (owner == null || index < 0 || index >= owner.Items.Count)
+ throw new ArgumentOutOfRangeException("index");
+
+ _bringIntoViewIndex = index;
+ InvalidateMeasure();
+ if (index >= _itemLayouts.Count)
+ return;
+
+ Rect item = _itemLayouts[index];
+ if (item.IsEmpty)
+ return;
+
+ double offset = _scrollOffset.Y;
+ if (item.Top < offset)
+ offset = item.Top;
+ else if (item.Bottom > offset + _viewportSize.Height)
+ offset = item.Bottom - _viewportSize.Height;
+ SetVerticalOffset(offset);
+ }
+
+ private void EnsurePendingItemVisible(double viewportHeight)
+ {
+ if (_bringIntoViewIndex < 0 || _bringIntoViewIndex >= _itemLayouts.Count)
+ return;
+
+ Rect item = _itemLayouts[_bringIntoViewIndex];
+ if (item.IsEmpty)
+ return;
+
+ if (item.Top < _scrollOffset.Y)
+ _scrollOffset.Y = item.Top;
+ else if (item.Bottom > _scrollOffset.Y + viewportHeight)
+ _scrollOffset.Y = Math.Max(item.Top, item.Bottom - viewportHeight);
+ ClampVerticalOffset();
+ }
+
+ #region IScrollInfo
+
+ public bool CanHorizontallyScroll { get; set; }
+
+ private bool _canVerticallyScroll;
+ public bool CanVerticallyScroll
+ {
+ get { return _canVerticallyScroll; }
+ set
+ {
+ if (_canVerticallyScroll == value)
+ return;
+ _canVerticallyScroll = value;
+ if (!value)
+ _scrollOffset.Y = 0;
+ InvalidateMeasure();
+ }
+ }
+
+ public double ExtentWidth { get { return _extentSize.Width; } }
+ public double ExtentHeight { get { return _extentSize.Height; } }
+ public double ViewportWidth { get { return _viewportSize.Width; } }
+ public double ViewportHeight { get { return _viewportSize.Height; } }
+ public double HorizontalOffset { get { return 0; } }
+ public double VerticalOffset { get { return _scrollOffset.Y; } }
+ public ScrollViewer ScrollOwner
+ {
+ get { return _scrollOwner; }
+ set
+ {
+ if (_scrollOwner == value)
+ return;
+ _scrollOwner = value;
+ InvalidateMeasure();
+ }
+ }
+
+ public void LineUp() { SetVerticalOffset(VerticalOffset - ScrollLineAmount); }
+ public void LineDown() { SetVerticalOffset(VerticalOffset + ScrollLineAmount); }
+ public void LineLeft() { }
+ public void LineRight() { }
+ public void MouseWheelUp() { SetVerticalOffset(VerticalOffset - ScrollLineAmount * 3); }
+ public void MouseWheelDown() { SetVerticalOffset(VerticalOffset + ScrollLineAmount * 3); }
+ public void MouseWheelLeft() { }
+ public void MouseWheelRight() { }
+ public void PageUp() { SetVerticalOffset(VerticalOffset - ViewportHeight); }
+ public void PageDown() { SetVerticalOffset(VerticalOffset + ViewportHeight); }
+ public void PageLeft() { }
+ public void PageRight() { }
+
+ public void SetHorizontalOffset(double offset)
+ {
+ if (double.IsNaN(offset))
+ throw new ArgumentOutOfRangeException("offset");
+ _scrollOffset.X = 0;
+ }
+
+ public void SetVerticalOffset(double offset)
+ {
+ if (double.IsNaN(offset))
+ throw new ArgumentOutOfRangeException("offset");
+ if (!CanVerticallyScroll)
+ offset = 0;
+ if (double.IsInfinity(offset))
+ offset = offset > 0 ? double.MaxValue : 0;
+
+ double maxOffset = Math.Max(0, ExtentHeight - ViewportHeight);
+ offset = Math.Max(0, Math.Min(offset, maxOffset));
+ if (_scrollOffset.Y != offset)
+ {
+ _scrollOffset.Y = offset;
+ InvalidateMeasure();
+ InvalidateArrange();
+ if (_scrollOwner != null)
+ _scrollOwner.InvalidateScrollInfo();
+ }
+ }
+
+ public Rect MakeVisible(Visual visual, Rect rectangle)
+ {
+ if (visual == null || rectangle.IsEmpty || Children.Count == 0)
+ return Rect.Empty;
+
+ DependencyObject current = visual;
+ while (current != null && current != this && !(current is UIElement && Children.Contains((UIElement)current)))
+ current = VisualTreeHelper.GetParent(current);
+ if (current == null || current == this)
+ return Rect.Empty;
+
+ int itemIndex = GetVirtualItemIndex(current);
+ if (itemIndex < 0 || itemIndex >= _itemLayouts.Count)
+ return Rect.Empty;
+
+ Rect visible = visual.TransformToAncestor(this).TransformBounds(rectangle);
+
+ double previousOffset = _scrollOffset.Y;
+ double desiredOffset = previousOffset;
+ if (visible.Top < 0)
+ desiredOffset += visible.Top;
+ else if (visible.Bottom > _viewportSize.Height)
+ desiredOffset += visible.Bottom - _viewportSize.Height;
+ SetVerticalOffset(desiredOffset);
+
+ double appliedDelta = _scrollOffset.Y - previousOffset;
+ double top = Math.Max(0, visible.Top - appliedDelta);
+ double bottom = Math.Min(_viewportSize.Height, visible.Bottom - appliedDelta);
+ if (bottom <= top)
+ return Rect.Empty;
+ return new Rect(visible.X, top, visible.Width, bottom - top);
+ }
+
+ #endregion
+ }
+}
diff --git a/src/WPFDevelopers.Shared/Controls/WaterfallPanel/WaterfallPanel.cs b/src/WPFDevelopers.Shared/Controls/WaterfallPanel/WaterfallPanel.cs
new file mode 100644
index 00000000..505ab329
--- /dev/null
+++ b/src/WPFDevelopers.Shared/Controls/WaterfallPanel/WaterfallPanel.cs
@@ -0,0 +1,254 @@
+using System;
+using System.Collections.Generic;
+using System.Windows.Controls;
+using System.Windows;
+
+namespace WPFDevelopers.Controls
+{
+ ///
+ /// Arranges items in equal-width columns, placing each item in the shortest column.
+ /// With an unbounded width, the widest item's natural desired width determines the column width.
+ /// Collapsed items do not occupy a column or contribute spacing.
+ /// As an ItemsControl panel, a finite ScrollViewer viewport with CanContentScroll enabled
+ /// supports UI virtualization. Other hosts generate and lay out all items.
+ ///
+ public partial class WaterfallPanel : VirtualizingPanel
+ {
+ private double[] _nonVirtualColumnHeights = new double[0];
+ private bool[] _columnHasChildren = new bool[0];
+ private readonly List _childLayouts = new List();
+ private double _columnWidth;
+ private int _actualColumns = 3;
+ private bool _usingVirtualization;
+
+ ///
+ /// Minimum column width for responsive layout; zero keeps the fixed Columns setting.
+ /// A container narrower than this value still displays one column.
+ ///
+ public double MinColumnWidth
+ {
+ get { return (double)GetValue(MinColumnWidthProperty); }
+ set { SetValue(MinColumnWidthProperty, value); }
+ }
+
+ public static readonly DependencyProperty MinColumnWidthProperty =
+ DependencyProperty.Register(
+ "MinColumnWidth", typeof(double), typeof(WaterfallPanel),
+ new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsMeasure, OnLayoutPropertyChanged),
+ value => (double)value >= 0 && !double.IsInfinity((double)value));
+
+ internal static int ResolveColumns(double availableWidth, int columns, double minColumnWidth, double spacing)
+ {
+ if (minColumnWidth == 0 || double.IsInfinity(availableWidth))
+ return columns;
+
+ return (int)Math.Max(1, Math.Min(int.MaxValue,
+ Math.Floor((availableWidth + spacing) / (minColumnWidth + spacing))));
+ }
+
+ protected override Size MeasureOverride(Size availableSize)
+ {
+ var children = InternalChildren;
+ _itemsControl = ItemsControl.GetItemsOwner(this);
+ var virtualize = _itemsControl != null && ScrollOwner != null &&
+ !double.IsInfinity(availableSize.Width) && !double.IsInfinity(availableSize.Height);
+ if (_usingVirtualization != virtualize)
+ {
+ RemoveAllRealizedChildren();
+ ResetItemMeasurements();
+ _usingVirtualization = virtualize;
+ _scrollOffset = new Point();
+ }
+ if (virtualize)
+ return MeasureVirtualized(availableSize);
+
+ if (_itemsControl != null)
+ GenerateAllContainers(children);
+
+ _extentSize = new Size();
+ _viewportSize = new Size();
+ if (ScrollOwner != null)
+ ScrollOwner.InvalidateScrollInfo();
+ return MeasureNonVirtualized(availableSize);
+ }
+
+ private void GenerateAllContainers(UIElementCollection children)
+ {
+ var generator = ItemContainerGenerator;
+ using (generator.StartAt(new System.Windows.Controls.Primitives.GeneratorPosition(-1, 0),
+ System.Windows.Controls.Primitives.GeneratorDirection.Forward, true))
+ {
+ for (var index = 0; index < _itemsControl.Items.Count; index++)
+ {
+ bool newlyRealized;
+ var child = (UIElement)generator.GenerateNext(out newlyRealized);
+ if (newlyRealized || !children.Contains(child))
+ {
+ InsertInternalChild(index, child);
+ generator.PrepareItemContainer(child);
+ }
+ SetVirtualItemIndex(child, index);
+ }
+ }
+ }
+
+ private Size MeasureNonVirtualized(Size availableSize)
+ {
+ _actualColumns = ResolveColumns(availableSize.Width, Columns, MinColumnWidth, Spacing);
+ SetValue(ActualColumnsPropertyKey, _actualColumns);
+ double width;
+ if (double.IsPositiveInfinity(availableSize.Width))
+ {
+ width = 0;
+ foreach (UIElement child in InternalChildren)
+ {
+ if (child.Visibility == Visibility.Collapsed)
+ continue;
+
+ child.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
+ width = Math.Max(width, child.DesiredSize.Width);
+ }
+ width = Math.Max(width, MinColumnWidth);
+ }
+ else
+ {
+ width = GetColumnWidth(availableSize.Width);
+ }
+
+ return MeasureChildren(width);
+ }
+
+ private double GetColumnWidth(double availableWidth)
+ {
+ return Math.Max(0, (availableWidth - (_actualColumns - 1) * Spacing) / _actualColumns);
+ }
+
+ private Size MeasureChildren(double width)
+ {
+ var columns = _actualColumns;
+ if (_nonVirtualColumnHeights.Length != columns)
+ {
+ _nonVirtualColumnHeights = new double[columns];
+ _columnHasChildren = new bool[columns];
+ }
+
+ Array.Clear(_nonVirtualColumnHeights, 0, _nonVirtualColumnHeights.Length);
+ Array.Clear(_columnHasChildren, 0, _columnHasChildren.Length);
+ _childLayouts.Clear();
+
+ _columnWidth = width;
+ var spacing = Spacing;
+ var panelDesiredSize = new Size(0, 0);
+
+ for (int i = 0; i < InternalChildren.Count; i++)
+ {
+ var child = InternalChildren[i];
+ if (child.Visibility == Visibility.Collapsed)
+ {
+ _childLayouts.Add(new Rect());
+ continue;
+ }
+
+ child.Measure(new Size(width, double.PositiveInfinity));
+
+ var columnIndex = 0;
+ for (var column = 1; column < columns; column++)
+ {
+ if (!_columnHasChildren[columnIndex])
+ break;
+
+ if (!_columnHasChildren[column] ||
+ _nonVirtualColumnHeights[column] < _nonVirtualColumnHeights[columnIndex])
+ {
+ columnIndex = column;
+ }
+ }
+
+ var x = columnIndex * (width + spacing);
+ var y = _nonVirtualColumnHeights[columnIndex];
+ if (_columnHasChildren[columnIndex])
+ {
+ y += spacing;
+ }
+
+ var childHeight = child.DesiredSize.Height;
+ _childLayouts.Add(new Rect(x, y, width, childHeight));
+ _nonVirtualColumnHeights[columnIndex] = y + childHeight;
+ _columnHasChildren[columnIndex] = true;
+
+ panelDesiredSize.Width = columns * width + (columns - 1) * spacing;
+ panelDesiredSize.Height = Math.Max(panelDesiredSize.Height, _nonVirtualColumnHeights[columnIndex]);
+ }
+
+ return panelDesiredSize;
+ }
+
+ protected override Size ArrangeOverride(Size finalSize)
+ {
+ if (_usingVirtualization)
+ {
+ ArrangeRealizedChildren();
+ return finalSize;
+ }
+ var columns = ResolveColumns(finalSize.Width, Columns, MinColumnWidth, Spacing);
+ var width = GetColumnWidth(finalSize.Width);
+ if (columns != _actualColumns)
+ {
+ _actualColumns = columns;
+ width = GetColumnWidth(finalSize.Width);
+ }
+ SetValue(ActualColumnsPropertyKey, _actualColumns);
+ if (width != _columnWidth || _nonVirtualColumnHeights.Length != columns ||
+ _childLayouts.Count != InternalChildren.Count)
+ {
+ MeasureChildren(width);
+ }
+
+ for (var i = 0; i < InternalChildren.Count; i++)
+ {
+ InternalChildren[i].Arrange(_childLayouts[i]);
+ }
+
+ return finalSize;
+ }
+
+ public void AddChild(UIElement element)
+ {
+ Children.Add(element);
+ }
+
+ ///
+ /// Gets or sets the positive number of columns.
+ ///
+ public int Columns
+ {
+ get { return (int)GetValue(ColumnsProperty); }
+ set { SetValue(ColumnsProperty, value); }
+ }
+
+ public static readonly DependencyProperty ColumnsProperty =
+ DependencyProperty.Register(
+ "Columns",
+ typeof(int),
+ typeof(WaterfallPanel),
+ new FrameworkPropertyMetadata(3, FrameworkPropertyMetadataOptions.AffectsMeasure, OnLayoutPropertyChanged),
+ value => (int)value > 0);
+
+ ///
+ /// Gets or sets the finite, nonnegative spacing between items and columns.
+ ///
+ public double Spacing
+ {
+ get { return (double)GetValue(SpacingProperty); }
+ set { SetValue(SpacingProperty, value); }
+ }
+
+ public static readonly DependencyProperty SpacingProperty =
+ DependencyProperty.Register(
+ "Spacing",
+ typeof(double),
+ typeof(WaterfallPanel),
+ new FrameworkPropertyMetadata(5.0, FrameworkPropertyMetadataOptions.AffectsMeasure, OnLayoutPropertyChanged),
+ value => (double)value >= 0 && !double.IsInfinity((double)value));
+ }
+}
diff --git a/src/WPFDevelopers.Shared/Core/Helpers/PanelHelper.cs b/src/WPFDevelopers.Shared/Core/Helpers/PanelHelper.cs
index 093d3914..702c13bc 100644
--- a/src/WPFDevelopers.Shared/Core/Helpers/PanelHelper.cs
+++ b/src/WPFDevelopers.Shared/Core/Helpers/PanelHelper.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
@@ -7,6 +8,14 @@ namespace WPFDevelopers.Helpers
{
public class PanelHelper : DependencyObject
{
+ public static readonly DependencyProperty SpacingProperty =
+ DependencyProperty.RegisterAttached("Spacing", typeof(double), typeof(PanelHelper),
+ new PropertyMetadata(0d, OnSpacingChanged),
+ value => (double)value >= 0 && !double.IsNaN((double)value) && !double.IsInfinity((double)value));
+
+ private static readonly DependencyProperty SpacingStateProperty =
+ DependencyProperty.RegisterAttached("SpacingState", typeof(SpacingState), typeof(PanelHelper));
+
public static double GetSpacing(DependencyObject obj)
{
return (double)obj.GetValue(SpacingProperty);
@@ -17,118 +26,163 @@ public static void SetSpacing(DependencyObject obj, double value)
obj.SetValue(SpacingProperty, value);
}
- public static readonly DependencyProperty SpacingProperty =
- DependencyProperty.RegisterAttached("Spacing", typeof(double), typeof(PanelHelper), new UIPropertyMetadata(0d, OnSpacingChanged));
-
private static void OnSpacingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
- if (d is Panel panel)
+ var panel = d as Panel;
+ if (panel == null) return;
+ var state = (SpacingState)panel.GetValue(SpacingStateProperty);
+ if ((double)e.NewValue == 0)
{
- double newValue = (double)e.NewValue;
- double oldValue = (double)e.OldValue;
- if (panel.IsLoaded)
- {
- UpdateChildrenSpacing(panel, newValue);
- }
- else
- {
- panel.Loaded -= OnPanelLoaded;
- panel.Loaded += OnPanelLoaded;
- panel.SetValue(SpacingProperty, newValue);
- }
+ if (state == null) return;
+ state.Detach();
+ panel.ClearValue(SpacingStateProperty);
+ return;
}
+ if (state == null)
+ {
+ state = new SpacingState(panel);
+ panel.SetValue(SpacingStateProperty, state);
+ }
+ state.Update();
}
- private static void OnPanelLoaded(object sender, RoutedEventArgs e)
+ private sealed class ChildMargin
{
- if (sender is Panel panel)
- {
- double spacing = (double)panel.GetValue(SpacingProperty);
- UpdateChildrenSpacing(panel, spacing);
- panel.Loaded -= OnPanelLoaded;
- }
+ internal Thickness Original;
+ internal Thickness Applied;
+ internal bool HadLocalValue;
}
- private static void UpdateChildrenSpacing(Panel panel, double spacing)
+ private sealed class SpacingState
{
- if (panel is StackPanel sp)
+ private readonly Panel _panel;
+ private readonly Dictionary _margins =
+ new Dictionary();
+ private bool _updating;
+
+ internal SpacingState(Panel panel)
{
- var orientation = GetEffectiveOrientation(sp);
- for (int i = 0; i < panel.Children.Count; i++)
- {
- if (panel.Children[i] is FrameworkElement fe)
- {
- bool isLast = i == panel.Children.Count - 1;
- if (orientation == Orientation.Horizontal)
- fe.Margin = new Thickness(spacing, 0, isLast ? 0 : spacing, 0);
- else
- fe.Margin = new Thickness(0, spacing, 0, isLast ? 0 : spacing);
- }
- }
+ _panel = panel;
+ panel.Loaded += OnLoaded;
+ panel.Unloaded += OnUnloaded;
+ if (panel.IsLoaded) panel.LayoutUpdated += OnLayoutUpdated;
}
- else if (panel is WrapPanel wp)
+
+ private void OnLoaded(object sender, RoutedEventArgs e)
{
- var orientation = GetEffectiveOrientation(wp);
- for (int i = 0; i < panel.Children.Count; i++)
- {
- if (panel.Children[i] is FrameworkElement fe)
- {
- bool isLast = i == panel.Children.Count - 1;
- if (orientation == Orientation.Horizontal)
- fe.Margin = new Thickness(spacing, 0, isLast ? 0 : spacing, 0);
- else
- fe.Margin = new Thickness(0, spacing, 0, isLast ? 0 : spacing);
- }
- }
+ _panel.LayoutUpdated -= OnLayoutUpdated;
+ _panel.LayoutUpdated += OnLayoutUpdated;
+ Update();
}
- else if (panel is UniformGrid ug)
+
+ private void OnUnloaded(object sender, RoutedEventArgs e)
{
- int columns = ug.Columns;
- int rows = ug.Rows;
- if (columns == 0 && rows == 0)
- columns = rows = (int)Math.Ceiling(Math.Sqrt(panel.Children.Count));
- else if (columns == 0)
- columns = (panel.Children.Count + rows - 1) / rows;
- else if (rows == 0)
- rows = (panel.Children.Count + columns - 1) / columns;
-
- for (int i = 0; i < panel.Children.Count; i++)
- {
- if (panel.Children[i] is FrameworkElement fe)
- {
- int col = i % columns;
- int row = i / columns;
- bool isFirstRow = row == 0;
- bool isFirstCol = col == 0;
- bool isLastInRow = col == columns - 1;
- bool isLastInCol = row == rows - 1;
- fe.Margin = new Thickness(
- isFirstCol ? spacing : 0,
- isFirstRow ? spacing : 0,
- isLastInRow ? 0 : spacing,
- isLastInCol ? 0 : spacing);
- }
- }
+ _panel.LayoutUpdated -= OnLayoutUpdated;
+ RestoreMargins();
}
- else
+
+ private void OnLayoutUpdated(object sender, EventArgs e)
{
- for (int i = 0; i < panel.Children.Count; i++)
+ Update();
+ }
+
+ internal void Detach()
+ {
+ _panel.Loaded -= OnLoaded;
+ _panel.Unloaded -= OnUnloaded;
+ _panel.LayoutUpdated -= OnLayoutUpdated;
+ RestoreMargins();
+ }
+
+ private void RestoreMargins()
+ {
+ foreach (var entry in _margins) Restore(entry.Key, entry.Value);
+ _margins.Clear();
+ }
+
+ internal void Update()
+ {
+ if (_updating || !_panel.IsLoaded) return;
+ _updating = true;
+ try
{
- if (panel.Children[i] is FrameworkElement fe)
+ var children = new List();
+ foreach (UIElement child in _panel.Children)
+ {
+ var element = child as FrameworkElement;
+ if (element != null) children.Add(element);
+ }
+ var removed = new List();
+ foreach (var entry in _margins)
+ {
+ if (!children.Contains(entry.Key)) removed.Add(entry.Key);
+ }
+ foreach (var child in removed)
{
- fe.Margin = new Thickness(spacing);
+ Restore(child, _margins[child]);
+ _margins.Remove(child);
+ }
+
+ var last = children.FindLast(element => element.Visibility != Visibility.Collapsed);
+ var spacing = GetSpacing(_panel);
+ foreach (var child in children)
+ {
+ ChildMargin margin;
+ if (!_margins.TryGetValue(child, out margin))
+ {
+ margin = new ChildMargin
+ {
+ Original = child.Margin,
+ Applied = child.Margin,
+ HadLocalValue = child.ReadLocalValue(FrameworkElement.MarginProperty) != DependencyProperty.UnsetValue
+ };
+ _margins.Add(child, margin);
+ }
+ if (child.Margin != margin.Applied)
+ {
+ margin.Original = child.Margin;
+ margin.HadLocalValue = child.ReadLocalValue(FrameworkElement.MarginProperty) != DependencyProperty.UnsetValue;
+ }
+ var gap = new Thickness();
+ if (child.Visibility != Visibility.Collapsed)
+ {
+ var stack = _panel as StackPanel;
+ if (stack != null)
+ {
+ if (child != last)
+ gap = stack.Orientation == Orientation.Horizontal
+ ? new Thickness(0, 0, spacing, 0) : new Thickness(0, 0, 0, spacing);
+ }
+ else if (_panel is WrapPanel || _panel is UniformGrid)
+ {
+ gap = new Thickness(spacing / 2);
+ }
+ else
+ {
+ gap = new Thickness(spacing);
+ }
+ }
+ margin.Applied = new Thickness(
+ margin.Original.Left + gap.Left, margin.Original.Top + gap.Top,
+ margin.Original.Right + gap.Right, margin.Original.Bottom + gap.Bottom);
+ if (child.Margin != margin.Applied)
+ child.SetCurrentValue(FrameworkElement.MarginProperty, margin.Applied);
}
}
+ finally
+ {
+ _updating = false;
+ }
}
- }
- private static Orientation GetEffectiveOrientation(Panel panel)
- {
- if (panel is StackPanel sp)
- return sp.Orientation;
- if (panel is WrapPanel wp)
- return wp.Orientation;
- return Orientation.Horizontal;
+ private static void Restore(FrameworkElement child, ChildMargin margin)
+ {
+ if (child.Margin != margin.Applied) return;
+ if (margin.HadLocalValue)
+ child.SetCurrentValue(FrameworkElement.MarginProperty, margin.Original);
+ else
+ child.ClearValue(FrameworkElement.MarginProperty);
+ }
}
}
}
diff --git a/src/WPFDevelopers.Shared/Core/Helpers/Win32.cs b/src/WPFDevelopers.Shared/Core/Helpers/Win32.cs
index 7e26d0fe..918586a0 100644
--- a/src/WPFDevelopers.Shared/Core/Helpers/Win32.cs
+++ b/src/WPFDevelopers.Shared/Core/Helpers/Win32.cs
@@ -178,6 +178,8 @@ public static extern bool BitBlt(IntPtr hdc, int nXDest, int nYDest, int nWidth,
public static bool EnableDarkModeForWindow(HwndSource source, bool enable)
{
+ if (source == null || source.Handle == IntPtr.Zero)
+ return false;
int darkMode = enable ? 1 : 0;
int hr = DwmSetWindowAttribute(source.Handle, DwmWindowAttributes.UseImmersiveDarkMode, ref darkMode, sizeof(int));
return hr >= 0;
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;
+ }
+ }
+}
diff --git a/src/WPFDevelopers.Shared/Languages/Language.en-US.resx b/src/WPFDevelopers.Shared/Languages/Language.en-US.resx
index 93a32070..71f0e74f 100644
--- a/src/WPFDevelopers.Shared/Languages/Language.en-US.resx
+++ b/src/WPFDevelopers.Shared/Languages/Language.en-US.resx
@@ -207,4 +207,10 @@
Next
+
+ Back to top
+
+
+ Back to bottom
+
\ No newline at end of file
diff --git a/src/WPFDevelopers.Shared/Languages/Language.ko-KR.resx b/src/WPFDevelopers.Shared/Languages/Language.ko-KR.resx
index ce95e53f..afd986b0 100644
--- a/src/WPFDevelopers.Shared/Languages/Language.ko-KR.resx
+++ b/src/WPFDevelopers.Shared/Languages/Language.ko-KR.resx
@@ -207,4 +207,10 @@
다음
+
+ 맨 위로
+
+
+ 맨 아래로
+
\ No newline at end of file
diff --git a/src/WPFDevelopers.Shared/Languages/Language.resx b/src/WPFDevelopers.Shared/Languages/Language.resx
index b8584fef..14e17435 100644
--- a/src/WPFDevelopers.Shared/Languages/Language.resx
+++ b/src/WPFDevelopers.Shared/Languages/Language.resx
@@ -187,4 +187,10 @@
下一页
+
+ 返回顶部
+
+
+ 返回底部
+
\ No newline at end of file
diff --git a/src/WPFDevelopers.Shared/Styles/Styles.ComboBox.xaml b/src/WPFDevelopers.Shared/Styles/Styles.ComboBox.xaml
index 91d36ef5..df43e611 100644
--- a/src/WPFDevelopers.Shared/Styles/Styles.ComboBox.xaml
+++ b/src/WPFDevelopers.Shared/Styles/Styles.ComboBox.xaml
@@ -12,6 +12,7 @@
diff --git a/src/WPFDevelopers.Shared/Styles/Styles.DatePicker.xaml b/src/WPFDevelopers.Shared/Styles/Styles.DatePicker.xaml
index bae2c9d1..37048554 100644
--- a/src/WPFDevelopers.Shared/Styles/Styles.DatePicker.xaml
+++ b/src/WPFDevelopers.Shared/Styles/Styles.DatePicker.xaml
@@ -509,6 +509,15 @@
TargetType="{x:Type DatePickerTextBox}">
+
+
+
+
+
+
+
+
+
@@ -640,4 +649,4 @@
-
\ No newline at end of file
+
diff --git a/src/WPFDevelopers.Shared/Styles/Styles.GridSplitter.xaml b/src/WPFDevelopers.Shared/Styles/Styles.GridSplitter.xaml
index 24c2a872..51cba7bc 100644
--- a/src/WPFDevelopers.Shared/Styles/Styles.GridSplitter.xaml
+++ b/src/WPFDevelopers.Shared/Styles/Styles.GridSplitter.xaml
@@ -1,4 +1,7 @@
-
+
@@ -13,18 +16,45 @@
-
\ No newline at end of file
+
diff --git a/src/WPFDevelopers.Shared/Styles/Styles.ScrollBar.xaml b/src/WPFDevelopers.Shared/Styles/Styles.ScrollBar.xaml
index eecf4221..0d10c88a 100644
--- a/src/WPFDevelopers.Shared/Styles/Styles.ScrollBar.xaml
+++ b/src/WPFDevelopers.Shared/Styles/Styles.ScrollBar.xaml
@@ -40,10 +40,20 @@
+
+
+
+
+
+
+
+
+
+
@@ -61,10 +71,20 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/src/WPFDevelopers.Shared/Themes/Basic/Dark.Color.xaml b/src/WPFDevelopers.Shared/Themes/Basic/Dark.Color.xaml
index 08e4d3e5..0ab5ae52 100644
--- a/src/WPFDevelopers.Shared/Themes/Basic/Dark.Color.xaml
+++ b/src/WPFDevelopers.Shared/Themes/Basic/Dark.Color.xaml
@@ -21,6 +21,17 @@
po:Freeze="True"
Color="{StaticResource WD.RegularTextColor}" />
+ #606266
+
+ #909399
+
+
#323232
-
-
M384 690l452-452 60 60-512 512-238-238 60-60z
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
@@ -86,4 +84,9 @@
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
diff --git a/src/WPFDevelopers.Shared/Themes/Basic/Light.Color.xaml b/src/WPFDevelopers.Shared/Themes/Basic/Light.Color.xaml
index 90ff9007..812b981c 100644
--- a/src/WPFDevelopers.Shared/Themes/Basic/Light.Color.xaml
+++ b/src/WPFDevelopers.Shared/Themes/Basic/Light.Color.xaml
@@ -16,6 +16,18 @@
x:Key="WD.RegularTextBrush"
po:Freeze="True"
Color="{StaticResource WD.RegularTextColor}" />
+
+ #C0C4CC
+
+ #909399
+
+
#FFFFFF
-
-
-
+ VerticalAlignment="Top"
+ SelectedItem="{Binding ColorType, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
\ No newline at end of file
+
diff --git a/src/WPFDevelopers.Shared/Themes/DateRangePicker.xaml b/src/WPFDevelopers.Shared/Themes/DateRangePicker.xaml
index 7eae1c94..143a03b3 100644
--- a/src/WPFDevelopers.Shared/Themes/DateRangePicker.xaml
+++ b/src/WPFDevelopers.Shared/Themes/DateRangePicker.xaml
@@ -7,6 +7,28 @@
+
+ Style="{StaticResource WD.DateRangePickerTextBox}" />
+ Style="{StaticResource WD.DateRangePickerTextBox}" />
-
\ No newline at end of file
+
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 @@
+
\ No newline at end of file
diff --git a/src/WPFDevelopers.Shared/Themes/Theme40.txt b/src/WPFDevelopers.Shared/Themes/Theme40.txt
index 8c1db594..676f8dea 100644
--- a/src/WPFDevelopers.Shared/Themes/Theme40.txt
+++ b/src/WPFDevelopers.Shared/Themes/Theme40.txt
@@ -55,6 +55,8 @@ StarrySky.xaml
Magnifier.xaml
Gauge.xaml
Step.xaml
+Timeline.xaml
+WaterfallItemsControl.xaml
Segmented.xaml
MultiSelectComboBox.xaml
Mask.xaml
diff --git a/src/WPFDevelopers.Shared/Themes/Theme45x.txt b/src/WPFDevelopers.Shared/Themes/Theme45x.txt
index 76993da1..4ff47e7c 100644
--- a/src/WPFDevelopers.Shared/Themes/Theme45x.txt
+++ b/src/WPFDevelopers.Shared/Themes/Theme45x.txt
@@ -56,6 +56,8 @@ StarrySky.xaml
Magnifier.xaml
Gauge.xaml
Step.xaml
+Timeline.xaml
+WaterfallItemsControl.xaml
Segmented.xaml
MultiSelectComboBox.xaml
Mask.xaml
diff --git a/src/WPFDevelopers.Shared/Themes/TimePicker.xaml b/src/WPFDevelopers.Shared/Themes/TimePicker.xaml
index 62926d01..79fa3ea5 100644
--- a/src/WPFDevelopers.Shared/Themes/TimePicker.xaml
+++ b/src/WPFDevelopers.Shared/Themes/TimePicker.xaml
@@ -98,7 +98,6 @@
-
+
+
+
+
diff --git a/src/WPFDevelopers.Shared/Themes/WaterfallItemsControl.xaml b/src/WPFDevelopers.Shared/Themes/WaterfallItemsControl.xaml
new file mode 100644
index 00000000..4abecb3f
--- /dev/null
+++ b/src/WPFDevelopers.Shared/Themes/WaterfallItemsControl.xaml
@@ -0,0 +1,53 @@
+
+
+
+
diff --git a/src/WPFDevelopers.Shared/WPFDevelopers.Shared.projitems b/src/WPFDevelopers.Shared/WPFDevelopers.Shared.projitems
index b70ff835..b4465888 100644
--- a/src/WPFDevelopers.Shared/WPFDevelopers.Shared.projitems
+++ b/src/WPFDevelopers.Shared/WPFDevelopers.Shared.projitems
@@ -24,6 +24,7 @@
+
@@ -77,7 +78,9 @@
-
+
+
+
@@ -85,6 +88,10 @@
+
+
+
+
@@ -234,6 +241,7 @@
+
@@ -585,6 +593,14 @@
Designer
MSBuild:Compile
+
+ Designer
+ MSBuild:Compile
+
+
+ MSBuild:Compile
+ Designer
+
Designer
MSBuild:Compile
@@ -690,4 +706,4 @@
-
+
\ No newline at end of file