Consider unsealing the Render() of the Panel? #15992
Replies: 8 comments 1 reply
-
+1 ! |
Beta Was this translation helpful? Give feedback.
-
+1 me too |
Beta Was this translation helpful? Give feedback.
-
It is sealed because we may want to change how things work in the future and if it wasn't sealed, that may lead to conflicts and breaking changes. Also I suggest to just add the sepator to ContainerItemTheme and if needed hide it for the last item. We have nth child selectors which could be useful here as well. |
Beta Was this translation helpful? Give feedback.
-
@timunie Thank your for your reply! Yes, I do this now. But it feels that putting the separator into the item container template is not lightweight enough. I should at least add a panel and a separator. In addition, I have to think about the layout of the separators in my mind so that they are accurately placed in the center of the two containers, which is troublesome to do. Even if I may need to place similar separators in different types of list controls, I need to modify the control template of each list container. Unsealing the Panel's Render function will give the Panel more flexible extensibility, although it is optional. If the user overrides the panel's Render function, then the user needs to be responsible for it. Render will only perform some additional auxiliary drawing and will not have an additional impact on the main function of the Panel-layout, which seems to be no breaking change. In contrast, allowing users to control measurement and layout arrangements seems to be more likely to cause conflicts and breaking changes, but this is inevitable, right? |
Beta Was this translation helpful? Give feedback.
-
Unfortunately, it's not that simple, particularly for selectable items. The separator will visually appear as contained in the selectable/selected item, which does not make sense. It still doesn't mean that overriding To create the separators as visual children, it is as "simple" as overriding this method appropriately: Avalonia/src/Avalonia.Controls/Panel.cs Line 134 in 82e3613 It's not very easy, but it should be maintainable and work well with virtualization if implemented correctly. |
Beta Was this translation helpful? Give feedback.
-
That's right. This is a reasonable approach, if we only add separators to the list and do not do other operations such as iteratoring visual children. Whether the separator is added in the control template or in the Children of the Panel, it is always a Visual in the visual tree. In some complex scenarios, we need to give them more attention. What I mean is that we can use different ways to achieve this goal in different scenarios. Whether it is overriding the control template, overriding the Panel's ChildrenChanged, or overriding Render, these methods may be suitable for various scenarios. If the Render method can be unsealed, the Panel will gain greater flexibility, even if this flexibility is not reflected in the scenario of adding separators, in some cases. |
Beta Was this translation helpful? Give feedback.
-
can this be simplify in any way |
Beta Was this translation helpful? Give feedback.
-
Agree, this change was unfortunate. My ugly workaround is: https://github.com/BAndysc/WoWDatabaseEditor/blob/ad03280fc13e3544e46d0b1ace550973c72ef4f6/AvaloniaStyles/Controls/ControlRenderer.cs Basically, it inserts an extra Control as the first child of the RenderedPanel, which is used as a "renderer" for the Render method. |
Beta Was this translation helpful? Give feedback.
-
Is your feature request related to a problem? Please describe.
I would like to put separators between some ListBoxItem. Just like :
Item | Item | Item
So I want to extend the StackPanel and render some separators on it. It is the simplest way to do that, I think.
BUT, the Render() of Panel is sealed.
Describe the solution you'd like
Could you please unseal the Render() of the Panel. I can not come out why it is sealed, in my opinion.
Describe alternatives you've considered
No response
Additional context
No response
Beta Was this translation helpful? Give feedback.
All reactions