"CornerRadius" is a misunderstanding. #5594
Replies: 3 comments 24 replies
-
Conceptually I think the answer here is simple. CornerRadius should be alongside BorderThickness property. In WPF/UWP BorderThickness is not part of UIElement or FrameworkElement, it is part of Border and Individual controls have this property themselves. I don't think its in all controls (even the ones that don't make sense) as you imply. Avalonia should do the same and only add it to Controls where it makes sense. About the separation of concepts: only controls where a corner radius makes sense have the property. Setting any radius to zero turns it off. All information is clear. Your assumption that all controls have a corner radius property even if it doesn't make sense is incorrect I think. The existence of the property itself fills in the missing information you are looking for. |
Beta Was this translation helpful? Give feedback.
-
I should also add, I think the group of buttons you mentioned is an interesting example. This ideally should be a separate control (like ButtonGroup/SegmentedControl WinUI discussionor the RadioButtons group control). However, this could be generalized and a 'GroupedContainer' parent control could be created. This grouped container would take care of managing border/corner radius of children along with orientation. The container would have the properties that would apply to the group as a whole. |
Beta Was this translation helpful? Give feedback.
-
maybe the whole problem is that Avalonia is missing first-child and last-child selector https://quirksmode.org/css/selectors/firstchild.html edit: |
Beta Was this translation helpful? Give feedback.
-
Hi,
Recently, while working on a PR to port the WinUI
Expander
style to Avalonia, I ran into some trouble stemming from how WinUI has aCornerRadius
property on most controls, while Avalonia does not, and was reminded of an observation I made a while ago.Metaphorically speaking, a
CornerRadius
property on all applicable controls (as is the case withBorderThickness
) would ask the app developer a question:But I feel that this is an unfortunate, perhaps-misguided conflation of two questions, which should be able to be answered independently of one another:
This distinction is important. For example, take this example:

Here, we see three linked buttons, with only the left corners of the leftmost button and the right corners of the rightmost button being rounded. Currently, there is no built-in way to do this in Avalonia, WinUI, WPF, or any other XAML framework I know of, without forcibly answering both of the above questions. Avalonia's
/template/
selector element reduces the amount of redundancy caused by this, but still doesn't solve the underlying problem.This inability to answer one question without answering the other means a lot of hardcoded corner radii. These can and will later prove to be quite the nuisance, should the developer later decide to switch their app over to a new theme, or to provide multiple themes for the user to choose from, or if the app uses say, Avalonia's Fluent theme, and an Avalonia update changes the default corner radius for the Fluent theme, or any number of other such scenarios.
So that's the problem. Now, onto what I propose could be done about it.
For a Control library I've been working on, I experimented with a solution to this, which would allow these two questions to be answered independently of each other, as separate properties. That solution was as follows:
CornerRadius
but with fourbool
s instead of fourdouble
s, entitledCornerCurves
CornerCurves
(of typeCornerCurves
, predictably enough)CornerCurves
property and aCornerRadius
object, and produces a newCornerRadius
object, with each corner's radius being either that of the original inputCornerRadius
if theCornerCurves
object hadtrue
for that corner, or zero if theCornerCurves
object hadfalse
for that cornerMy exact implementation of this solution was flawed in various ways, but it did solve the problem: It allowed the app developer to answer only the first question ("Which of these corners should be rounded?"), while leaving the Avalonia theme still able to answer the second question ("What is the radius of a rounded corner?"), with no additional action from the developer being required.
I believe a similar solution can and should be implemented into Avalonia (albeit presumably not as an Attached property). I'm eager to do my part to do so, but want to hear what others think about both the problem and the proposed solution.
Also this would need a way to pass the value of aDynamicResource
into a converter, or failing that aStaticResource
...neither of which I've figured out a way to achieve, thus far...UPDATE: Following the discussion which took place in the responses to this conversation, I've come to realize that, while this is a real and valid problem, it's not nearly as big of a deal to most as I expected, to the point where a solution to it - or at least a solution as drastic as the one I proposed - would be more trouble than it's worth to most.
Maybe Avalonia should just follow WinUI's example here. If that ends up being the plan, I'd be more than happy to do what I can to help make it happen.
Beta Was this translation helpful? Give feedback.
All reactions