You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: hub/apps/develop/data-binding/data-binding-in-depth.md
+191Lines changed: 191 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -439,6 +439,197 @@ namespace ExampleNamespace
439
439
</Window>
440
440
```
441
441
442
+
### Mixing {x\:Bind} and {Binding} in a reusable Style
443
+
444
+
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}`.
445
+
446
+
Here's an example that shows how to create a reusable Button style that uses both binding approaches:
-**`{Binding}`** is used for properties that depend on the DataContext (ButtonBackgroundBrush, ButtonForegroundBrush, ButtonHoverBrush)
629
+
-**`{x:Bind}`** is used for properties that are compile-time known and belong to the ResourceDictionary itself (DefaultIndicatorBrush, DefaultPressedBrush)
630
+
- The style is reusable and can be applied to any Button
631
+
- Runtime theming is possible through the DataContext while still benefiting from the performance of `{x:Bind}` for static elements
632
+
442
633
## Event binding and ICommand
443
634
444
635
[{x:Bind}](/windows/uwp/xaml-platform/x-bind-markup-extension) supports a feature called event binding. With this feature, you can specify the handler for an event using a binding, which is an additional option on top of handling events with a method on the code-behind file. Let's say you have a `ListViewDoubleTapped` event handler on your `MainWindow` class.
Copy file name to clipboardExpand all lines: uwp/data-binding/data-binding-in-depth.md
+186Lines changed: 186 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -589,6 +589,192 @@ MainPage.xaml
589
589
</Page>
590
590
```
591
591
592
+
### Mixing {x\:Bind} and {Binding} in a reusable Style
593
+
594
+
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}.
595
+
596
+
Here's an example that shows how to create a reusable Button style that uses both binding approaches:
-**{Binding}** is used for properties that depend on the DataContext (ButtonBackgroundBrush, ButtonForegroundBrush, ButtonHoverBrush)
774
+
-**{x:Bind}** is used for properties that are compile-time known and belong to the ResourceDictionary itself (DefaultIndicatorBrush, DefaultPressedBrush)
775
+
- The style is reusable and can be applied to any Button
776
+
- Runtime theming is possible through the DataContext while still benefiting from the performance of {x:Bind} for static elements
777
+
592
778
## Event binding and ICommand
593
779
594
780
[{x:Bind}](../xaml-platform/x-bind-markup-extension.md) supports a feature called event binding. With this feature, you can specify the handler for an event using a binding, which is an additional option on top of handling events with a method on the code-behind file. Let's say you have a **RootFrame** property on your **MainPage** class.
0 commit comments