Replies: 3 comments 3 replies
-
This could also allow applying classes to child controls <Style Selector="Button.TopButton > TextBlock">
<ClassSetter Classes="h1"/>
<Style/> |
Beta Was this translation helpful? Give feedback.
-
I'm generally in favour of this idea, though I'm not sure about the priority part - could you explain your thoughts in more detail? The reason we've not implemented this before though is because we foresaw a couple of problems:
|
Beta Was this translation helpful? Give feedback.
-
We also have run into some scenarios where it would be handy to be able to add/remove classes to controls within a template. For instance, if you are theming a |
Beta Was this translation helpful? Give feedback.
-
There are several reasons why it would be great to be able to set classes in styles.
Since Styles can't use BasedOn I would propose the following syntax to be able to compose styles:
This would allow to only add classes (not remove them) so there would be no problem with recursion (E.g. Style A sets class B, style B sets class A would not be a problem).
The setters from the classes added by the ClassSetters are added in the priority as they are written e.g. prio would be (from highest to lowest)
I know the example with bigboldblue is trivial but I think that would be a great improvements to styles as you could wrap, append and compose existing styles easily and avoid duplications.
Also it would allow the often used scenario in WPF that you add a stlye that is applied without a key (e.g. only Button, in WPF TargetType="Button") that is based on a previously defined style. E.g. you define some button styles in App.xaml and inside one UserControl you would want to have all Buttons styled with the same style which is one from App.xaml. You could with that add a style to the user control that has a ClassSetter for that Style from App.xaml:
Beta Was this translation helpful? Give feedback.
All reactions