Description
It is common in XAML to set default values in Style Setters:
<Setter Property="Padding" Value="{ThemeResource TextControlThemePadding}" />
<Setter Property="Foreground" Value="{ThemeResource TextControlForeground}" />
<Setter Property="Background" Value="{ThemeResource TextControlBackground}" />
<Setter Property="BorderBrush" Value="{ThemeResource TextControlBorderBrush}" />
When writing a new custom dependency property, you can define the default value in code-behind as described by the current document, but you can also add it to the style for a templated control.
There should be a section here that describes the pros/cons of each approach, how they interact with one another, and when to use one approach over the other.
I believe there's ramifications on if you want to use them in Visual State Managers or other things like Template Binding, but I don't remember and not sure, was hoping the documentation would help remind me here.
If this is in some other XAML doc, then it should be referenced here, but this seemed like a good spot to talk about it and branch out elsewhere.
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
- ID: cf035b98-e0c9-50c2-45ad-1dd37b4f31b0
- Version Independent ID: 4434d33d-7a43-8181-26f2-414ac194c272
- Content: Custom dependency properties - UWP applications
- Content Source: windows-apps-src/xaml-platform/custom-dependency-properties.md
- Product: uwp
- Technology: platform
- GitHub Login: @jwmsft
- Microsoft Alias: jimwalk