From fa61254659cf6cfaeff0739c6cf1a824fc2275b2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 26 Aug 2025 19:19:55 +0000 Subject: [PATCH 1/3] Initial plan From 3863ed4953ec387e8d44489ed51069f5a65cc97f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 26 Aug 2025 19:26:40 +0000 Subject: [PATCH 2/3] Add comprehensive example of x:Bind and Binding in reusable Styles Co-authored-by: alvinashcraft <73072+alvinashcraft@users.noreply.github.com> --- .../data-binding/data-binding-in-depth.md | 191 ++++++++++++++++++ uwp/data-binding/data-binding-in-depth.md | 186 +++++++++++++++++ 2 files changed, 377 insertions(+) diff --git a/hub/apps/develop/data-binding/data-binding-in-depth.md b/hub/apps/develop/data-binding/data-binding-in-depth.md index 99affd2070..697fd4b980 100644 --- a/hub/apps/develop/data-binding/data-binding-in-depth.md +++ b/hub/apps/develop/data-binding/data-binding-in-depth.md @@ -439,6 +439,197 @@ namespace ExampleNamespace ``` +### Mixing {x:Bind} and {Binding} in a reusable Style + +While the previous example showed using `{x:Bind}` in DataTemplates, you can also create reusable Styles that combine both `{x:Bind}` and `{Binding}` markup extensions. This is useful when you want to bind some properties to compile-time known values using `{x:Bind}` and other properties to runtime DataContext values using `{Binding}`. + +Here's an example that shows how to create a reusable Button style that uses both binding approaches: + +TemplatesResourceDictionary.xaml + +``` xaml + + + + + + + + + + + + + +``` + +TemplatesResourceDictionary.xaml.cs + +``` csharp +// TemplatesResourceDictionary.xaml.cs +using Microsoft.UI; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Data; +using Microsoft.UI.Xaml.Media; + +namespace ExampleNamespace +{ + public partial class TemplatesResourceDictionary + { + public TemplatesResourceDictionary() + { + InitializeComponent(); + } + + // Properties for x:Bind - these are compile-time bound + public SolidColorBrush DefaultIndicatorBrush { get; } = + new SolidColorBrush(Colors.Green); + + public SolidColorBrush DefaultPressedBrush { get; } = + new SolidColorBrush(Colors.DarkGray); + } +} +``` + +Usage in MainWindow.xaml with a ViewModel that provides runtime values: + +``` xaml + + + + + + + + + + + + + + + + + + +