Can I create a custom control that lets me pass in children as XAML? #19781
-
|
I want to create a custom control that will wrap children with custom markup. My custom control is basically a panel, but with additional things added around its children. Using it would look like The XAML of MyCustomWrapper could look like The point is, I want be able to create and style some kind of container that adds a bunch of markup around some children, and the children must be passed in XAML along with the container's markup. I've looked at templated controls, but they seem to work by passing data in, and I want to pass markup in instead. The closest example I can find is in WPF (https://stackoverflow.com/questions/9094486/adding-children-to-usercontrol), but I can't seem to find the Avalonia equivalent of this. Can this be done? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
Types like Avalonia/src/Avalonia.Themes.Fluent/Controls/Button.xaml Lines 29 to 43 in 67a223d You aren't writing a To clarify the point about markup -- it's never passed. XAML is compiled to IL, bindings are created with compile-time safety. XAML isn't seen at runtime unless you're explicitly loading it through that path. Instead, you're running IL that has a lot of |
Beta Was this translation helpful? Give feedback.
Ok. I found what I'm looking for, the way Avalonia does it is a bit round-about, but it works. I should have actually started with the example of the control I wanted to make - I want to make the equivalent of the classic WPF GroupBox control, which I can use to wrap any child content in a square with a header, and some styling like padding etc. Searching for that specific use-case led to this piece of official Avalonia documentation (https://docs.avaloniaui.net/docs/tutorials/groupbox), which was a good start.
Instead of using the built-in
HeaderedContentControlAvalonia I made my own base, the source at https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Controls/Primitives/…