Template Bind all the Properties
Problem Statement
Developers want to easily change common properties on controls or item templates like Foreground, Background, BorderBrush, BorderThickness, Margin, Padding, CornerRadius, FontSize, FontFamily, Horizontal/Vertical[Content]Alignment etc...
The common XAML pattern is to do this with the property of the control and for XAML control templates to use template binding to enable that.
The Issue
It seems to be a common issue I'm seeing all the time now across how the current control templates have been redone in WinUI. There are many resources exposed from controls which is great, but instead of setting them in the Style for the component they're being used directly. Instead, they should be used in the Style as a Setter and then referenced using TemplateBinding within the control's template.
For instance, CornerRadius on GridViewItem isn't using TemplateBinding here (among other properties here which should be template bound):
|
CornerRadius='{ThemeResource GridViewItemCornerRadius}' |
Without this, folks either have to re-template the entire control (if there is no resource available) or try and override the resource, though there is a common issue with StaticResource not respecting overrides compared to ThemeResource (don't know if there's a tracking issue, #5457 seemed the closest?), so that doesn't always work.
Solution
This issue is requesting an overall audit across the entire set of styles to fix these issues now before they get reported by customers. As well, guidance for new controls during creation and review should audit these best practices like template binding and template naming so they can maintain a high-standard for enabling the customization XAML provides as a system to developers.
Without controls maintaining these patterns, the benefits of the XAML Styling system are diminished.
Related existing Issues reporting this same issue
Other General Style Issues for Audit
Template Bind all the Properties
Problem Statement
Developers want to easily change common properties on controls or item templates like
Foreground,Background,BorderBrush,BorderThickness,Margin,Padding,CornerRadius,FontSize,FontFamily,Horizontal/Vertical[Content]Alignmentetc...The common XAML pattern is to do this with the property of the control and for XAML control templates to use template binding to enable that.
The Issue
It seems to be a common issue I'm seeing all the time now across how the current control templates have been redone in WinUI. There are many resources exposed from controls which is great, but instead of setting them in the Style for the component they're being used directly. Instead, they should be used in the Style as a
Setterand then referenced usingTemplateBindingwithin the control's template.For instance,
CornerRadiusonGridViewItemisn't usingTemplateBindinghere (among other properties here which should be template bound):microsoft-ui-xaml/dev/CommonStyles/GridViewItem_themeresources_21h1.xaml
Line 177 in e59614e
Without this, folks either have to re-template the entire control (if there is no resource available) or try and override the resource, though there is a common issue with
StaticResourcenot respecting overrides compared toThemeResource(don't know if there's a tracking issue, #5457 seemed the closest?), so that doesn't always work.Solution
This issue is requesting an overall audit across the entire set of styles to fix these issues now before they get reported by customers. As well, guidance for new controls during creation and review should audit these best practices like template binding and template naming so they can maintain a high-standard for enabling the customization XAML provides as a system to developers.
Without controls maintaining these patterns, the benefits of the XAML Styling system are diminished.
Related existing Issues reporting this same issue
Other General Style Issues for Audit