Skip to content

Template Bind all the Properties #6945

@michael-hawker

Description

@michael-hawker

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions