-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Open
Description
Is your feature request related to a problem? Please describe.
Currenly Classes.className
syntax only supports boolean bindings, which toggle specified class name on the control:
<Border Classes.className="{Binding BooleanProp}" />
By itself this syntax is very convenient, but also very limiting for enum and string bindings.
For example, if developer wants to toggle classes depending on enum value without any C# code, they should somehow convert it to boolean expression, which can be written this:
<Border Classes.is-verbose="{Binding Verbosity, ConverterParameter={x:Static LogEventLevel.Verbose}, Converter={x:Static ObjectConverters.Equal}}" />
With custom converters this syntax can be slightly improved, but far from ideal.
Describe the solution you'd like
Extend existing syntax by allowing non-boolean bindings. Combined with StringFormat
when desired to customize property name.
<Border Classes.bind="{Binding Verbosity, StringFormat='vebosity-{0}'}" />
Where:
- "Classes.bind" is a reserved property.
- StringFormat is optional, when return property type is string or enum. Required for any other type.
- Flags enums are not supported (unless a custom converter).
- Single binding defines a group of class names, where only single one is set at a time.
It should also work with setters:
<Setter Property="Classes.bind" Value="{Binding Verbosity}" />
Problems:
- The tricky part is to draw a line between "this is a boolean binding" and a "this is an enum/string binding", especially when binding return type is unknown (reflection binding or converter are used). Unless we introduce a breaking change for any app that already used "Classes.bind" as a classname.
- With this syntax only single class binding is allowed per control. Since duplicated xml attributes are not allowed.
Describe alternatives you've considered
No response
Additional context
No response
kebox7, MrJul, bugrakurnaz, pressogh, fitdev and 2 more