Wpf: Make Setter.Value the ContentProperty for Setter

Created on 5 Dec 2018  路  4Comments  路  Source: dotnet/wpf

Currently, when you want to set the value of a setter to a complex object (e.g. control template), you have to specify the <Setter.Value> element:

<Style TargetType="Button">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Button">
                ...
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

But this element brings no value at all, it just adds noise. Making Value the ContentProperty for Setter would make the code a bit less verbose:

<Style TargetType="Button">
    <Setter Property="Template">
        <ControlTemplate TargetType="Button">
            ...
        </ControlTemplate>
    </Setter>
</Style>

(note: I tried to make this change, but I can't find the Setter class anywhere in the repo... nor can I find any of the controls. Where are they? Is there another repo?)

issue-type-api-suggestion issue-type-enhancement

Most helpful comment

This is such an obvious and simple thing, I'm now wondering why I didn't think of that 馃榿 Awesome idea

All 4 comments

Setter is in PresentationFramework.dll - that code is not yet in this repo. (System.Xaml to start).
Of course, if this change was wanted, you'd just add [ContentProperty("Value")] to the Setter class.

Setter is in PresentationFramework.dll - that code is not yet in this repo.

I'll wait, then!

Of course, if this change was wanted, you'd just add [ContentProperty("Value")] to the Setter class.

Yes, that's what I thought. I've been ranting about this for years, so I'll be glad to be able to fix it 馃槈

This is such an obvious and simple thing, I'm now wondering why I didn't think of that 馃榿 Awesome idea

Is there anything still blocking this feature? PR #745 has been open for months, can it be merged now that .NET Core 3.0 (and 3.1) has been released?

Was this page helpful?
0 / 5 - 0 ratings