diff --git a/docs/en/getting-started.md b/docs/en/getting-started.md index 6a87eda4..e1e3160a 100644 --- a/docs/en/getting-started.md +++ b/docs/en/getting-started.md @@ -1,4 +1,4 @@ -# WPFDevelopers Getting Started +# WPFDevelopers Getting Started > Get started with WPFDevelopers controls in your WPF project in three steps. @@ -73,7 +73,7 @@ Add the WD namespace and theme resources in `App.xaml`: | Configuration | Effect | |---------------|--------| -| `` | Default Light theme, 4px control corner radius (follows system Light/Dark on Windows 10+) | +| `` | Restores the previous theme mode; follows the system on first use, 4px control corner radius | | `` | Fixed light theme, 4px corner radius | | `` | Fixed dark theme, 4px corner radius | | `` | Custom theme color, 4px corner radius | @@ -82,6 +82,22 @@ Add the WD namespace and theme resources in `App.xaml`: > **Important**: `wd:Resources` must be placed **after** `Theme.xaml` in MergedDictionaries, otherwise the theme will not load correctly. +### High-DPI Border Clipping on Older .NET Framework Targets + +Applications targeting .NET Framework versions below 4.6 can clip borders when fixed-width controls combine `Margin` with `UseLayoutRounding` at scaling factors such as 125%. `PanelHelper.Spacing` adjusts the margins of direct children, so it can also trigger this behavior. + +Enable the layout-rounding fix introduced in .NET Framework 4.6 in the application's `App.config`, without removing `Width` or `Spacing`: + +```xml + + + + + +``` + +If `AppContextSwitchOverrides` already exists, append this switch to its `value`, separated by a semicolon, rather than adding another element. The fix requires .NET Framework 4.6 or later at runtime and an application restart. On earlier runtimes, setting `UseLayoutRounding="False"` on the affected control is a local workaround. + --- ## Step 3: Use Controls in XAML @@ -414,6 +430,26 @@ The sample navigation identifies these implementations and composed effects with ### Windows & Navigation +`wd:Window` includes a theme mode menu controlled by the `ShowTheme` dependency property (default: `False`): + +```xml + + + +``` + +Supported in `Normal` and `High` title bars. Hovering opens a Follow system / Light mode / Dark mode popup; leaving both the entry and popup dismisses it. The entry icon reflects the selected mode, with a checkmark on the right of the selected row. Keyboard users can focus the entry and press Space to open, use Up/Down to navigate, Space to confirm, and Escape to dismiss. Actual light/dark changes retain the circular reveal animation. `TitleBarLayout` remains available for custom content. This property does not control the accent-color picker, and the button is hidden without a title bar. + +Read or set the user's preference through `ThemeManager.Instance.Resources.ThemeMode` (`System`, `Light`, or `Dark`). `Theme` / `IsDarkTheme` report the effective theme. System changes do not overwrite the System preference; setting the existing `ThemeType.Default` still enables following the system. + +Theme preferences are automatically saved to `HKEY_CURRENT_USER\Software\WPFDevelopers\Applications\` and restored on the next launch. The `ThemeMode` string value is `System` (follow system), `Light` (light mode), or `Dark` (dark mode). Each application stores its preference separately. + +Runtime verification (replace `net48` with `net40` for the .NET 4.0 build): + +```powershell +powershell -NoProfile -STA -File .\tests\Window.Theme.SmokeTests.ps1 -AssemblyPath .\OutPut\net48\WPFDevelopers.dll +``` + | Control | Source | Example File | Description | |---------|--------|-------------|-------------| | `wd:Window` | NuGet | [MainWindow.xaml](../../src/WPFDevelopers.Samples.Shared/ExampleViews/MainWindow.xaml) | Custom window (ToolWindow / NoneTitleBar / Normal / HighTitleBar) | @@ -754,6 +790,96 @@ MessageBox.Show("Operation successful!", "Info", MessageBoxButton.OK, MessageBox --- +## Dialog + +`Dialog` displays custom forms or confirmation content using a `UserControl` or `Page`, with a mask, title, and confirm/cancel buttons. + +### Opening and validating input + +```csharp +var editor = new UserEditor(); // Your custom UserControl +var dialog = new WPFDevelopers.Controls.Dialog +{ + Title = "Edit user", + Content = editor, + Owner = this, + DialogWidth = 520 +}; +dialog.Closing += (sender, e) => +{ + if (e.Reason == WPFDevelopers.Controls.DialogCloseReason.Confirm) + e.Cancel = !editor.Validate(); // Keep open when validation fails +}; +if (await dialog.ShowAsync() == WPFDevelopers.Controls.DialogResult.Confirmed) +{ + Save(editor.DataContext); +} +``` + +Implement `Validate()` and `Save()` in your application. Validate input in `Closing` when confirming, set `e.Cancel = true` to keep the dialog open, and display an error in the content. WPF binding validation errors also prevent confirmation automatically. + +### Common options + +| Property/method | Default | Description | +|---|---|---| +| `Content` | null | Required; a `UserControl` or `Page` not placed in another container | +| `Title` | Empty string | Dialog title | +| `CornerRadius` | `10` | Corner radius; use `new CornerRadius(0)` for square corners | +| `Owner` | null | Parent window; finds the current window if omitted | +| `DialogWidth` / `DialogHeight` | `440` / `double.NaN` | Width and height; `double.NaN` sizes automatically | +| `ShowFooter` | true | Whether to show the footer buttons | +| `ConfirmText` / `CancelText` | null | Button labels; follow language settings by default | +| `IsConfirmEnabled` | true | Bindable confirmation button availability | +| `IsOpen` | false | Two-way open state; false requests cancellation | +| `ClosedCommand` | null | Runs after closure with a `DialogResult` parameter | +| `ShowAsync(owner = null)` | — | Opens the dialog and awaits `Confirmed` or `Canceled` | +| `Close(reason)` | `Cancel` | Requests closure, still running `Closing` validation | + +- Call on the UI thread. Only one dialog per owner is supported; do not change `Content` while open. +- Cancel does not roll back ViewModel changes. Use a working copy if edits must be discarded. +- Custom window templates need an `AdornerDecorator`. For a draggable independent window, use a custom `Window` with `MaskShowDialog()`. + +The example uses `await` (.NET 4.5+). On .NET 4.0 use the same API with a UI scheduler: + +```csharp +dialog.ShowAsync().ContinueWith(task => +{ + if (task.Result == WPFDevelopers.Controls.DialogResult.Confirmed) + Save(editor.DataContext); +}, TaskScheduler.FromCurrentSynchronizationContext()); +``` + +### MVVM + +Declare the dialog in `Resources`, not directly in the layout. Assign the ViewModel explicitly (`DialogViewModel` below is a previously declared resource): + +```xml + + + + + +``` + +Reference the dialog's DataContext from the opening button: + +```xml + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + - - + + + + + - - + + + + + + + - - @@ -311,12 +195,10 @@ - - - + diff --git a/src/WPFDevelopers.Net45x/Themes/Theme.xaml b/src/WPFDevelopers.Net45x/Themes/Theme.xaml index c7b39b33..a9cb8927 100644 --- a/src/WPFDevelopers.Net45x/Themes/Theme.xaml +++ b/src/WPFDevelopers.Net45x/Themes/Theme.xaml @@ -35,6 +35,9 @@ Normal Normal M384 690l452-452 60 60-512 512-238-238 60-60z + M12 2a10 10 0 1 0 10 10A7 7 0 0 1 12 2Z + M2 5H7 M11 5H22 M2 12H13 M17 12H22 M2 19H5 M9 19H22 M9 3A2 2 0 1 1 9 7A2 2 0 1 1 9 3 M15 10A2 2 0 1 1 15 14A2 2 0 1 1 15 10 M7 17A2 2 0 1 1 7 21A2 2 0 1 1 7 17 + M12 19a7 7 0 1 1 0-14 7 7 0 0 1 0 14Zm0-1.5a5.5 5.5 0 1 0 0-11 5.5 5.5 0 1 0 0 11Zm-5.657.157a.75.75 0 0 1 0 1.06l-1.768 1.768a.749.749 0 0 1-1.275-.326.749.749 0 0 1 .215-.734l1.767-1.768a.75.75 0 0 1 1.061 0ZM3.515 3.515a.75.75 0 0 1 1.06 0l1.768 1.768a.749.749 0 0 1-.326 1.275.749.749 0 0 1-.734-.215L3.515 4.575a.75.75 0 0 1 0-1.06ZM12 0a.75.75 0 0 1 .75.75v2.5a.75.75 0 0 1-1.5 0V.75A.75.75 0 0 1 12 0ZM4 12a.75.75 0 0 1-.75.75H.75a.75.75 0 0 1 0-1.5h2.5A.75.75 0 0 1 4 12Zm8 8a.75.75 0 0 1 .75.75v2.5a.75.75 0 0 1-1.5 0v-2.5A.75.75 0 0 1 12 20Zm12-8a.75.75 0 0 1-.75.75h-2.5a.75.75 0 0 1 0-1.5h2.5A.75.75 0 0 1 24 12Zm-6.343 5.657a.75.75 0 0 1 1.06 0l1.768 1.768a.751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018l-1.768-1.767a.75.75 0 0 1 0-1.061Zm2.828-14.142a.75.75 0 0 1 0 1.06l-1.768 1.768a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042l1.767-1.768a.75.75 0 0 1 1.061 0Z M 998 352 C 998 344 994 335 988 329 L 938 279 C 932 273 924 269 915 269 C 907 269 898 273 892 279 L 499 672 L 106 279 C 100 273 91 269 83 269 C 75 269 66 273 60 279 L 10 329 C 4 335 0 344 0 352 C 0 360 4 369 10 375 L 476 841 C 482 847 491 851 499 851 C 507 851 516 847 522 841 L 988 375 C 994 369 998 360 998 352 Z M8.1772461,11.029181 L10.433105, @@ -146,6 +149,7 @@ + @@ -685,36 +689,102 @@ - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - + @@ -920,15 +855,15 @@ - - - + + + + - - - + + @@ -938,7 +873,7 @@ - + @@ -950,7 +885,7 @@ - + @@ -974,21 +909,23 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + @@ -1005,28 +942,33 @@ - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1325,7 +1267,7 @@ - + @@ -1443,6 +1385,8 @@ + + + + + + + + + + + +