microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.34k stars 676 forks source link

WinUI AddVisualChild? #4833

Open arivoir opened 3 years ago

arivoir commented 3 years ago

Is there any way to add children of a control(or framework-element) dynamically?

I know I can create a control with a template and add a panel inside, but that ends up impacting performance. I want to make the visual tree as small as possible.

StephenLPeters commented 3 years ago

I don't think so. We don't directly expose a way to set children on arbitrary controls. Panels expose a children collections, which is the point of them. There might be something in XamlDirect, but I'm not familiar enough to say for sure.

arivoir commented 3 years ago

I didn't find anything in XamlDirect. It's a pity WinUI forces a poor performance approach

chrisglein commented 3 years ago

Doesn't seem like something XamlDirect would help with.

@arivoir Can you help us understand your scenario more? There is a gap here where there's no single API to add children (will depend on the type). I think the answer to your question is "no", but this could be reframed as a feature request.

arivoir commented 3 years ago

I need to implement something like Border, a control that can have an arbitrary child, and also the ability to draw a series of rectangles and paths behind the child as well as clipping the child. I can implement this like a templated control, the problem is defining all these elements and hiding the not used is poor in terms of performance. Having the ability to change the visuals of a control dynamically is perfect for these scenarios, like in WPF.