Support dynamic theming of Thickness based properties Margin and Spacing
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
Often we have specific sizes for margins that need to change dynamically depending on the density setting of an app. There is no easy way to do this without duplicating a lot of styles for various scenarios, because controls usually need different spacing values in the 4 directions. To allow dynamic theming of `Thickness` based properties you would have to write out all the combinations of possible spacings in the design and cardinal directions. Of course CSS is completely different from Xaml and not everyone likes it, but this is a scenario that has very good support in the web world. [Bootstrap](https://getbootstrap.com/docs/4.0/utilities/spacing/) for instance allows you to add multiple classes to combine spacing values. For example `mt3 ml1` adds a margin of 3 units to the top and a margin of 1 unit to the left for which unit is defined at the app styling level.
The problem in WPF is that since `Thickness` is a `struct` you cannot apply `DynamicResource` values to it's members. I'm not sure how to solve this, because due to compatibility `Thickness` cannot be changed into a `DependencyObject` with `DependencyProperty`s for `Left`, `Right`, `Top` and `Bottom`.
A very verbose way to accomplish this would be to write a `Behavior` with dependency properties for the cardinal directions that are proxied for the attached control. This would allow setting `DynamicResources` on the cardinal directions, but it is not a great approach since it circumvents the styling system.
Contributor guide
Assessment
This issue has not been assessed yet.