I need to create and add some items to a popup code-behind. It's easy to do this in XAML:
<Popup StaysOpen="False">
<DockPanel>
//Items here
</DockPanel>
</Popup>
I think "Child" is where I need to add my items but I don't see any "Add", "Items", "Source" or "Content" inside. Does anyone know how to do this?
Popup myPopup= new Popup();
myPopup.Child // ... need to add items there
Popup is a FrameworkElement and can have only one child (Child) => you cannot add multiple controls inside, but you can set Child to be any UIElement you want. For instance a DockPanel, and than use AddChild on the panel to add further controls.
myPopup.Child = new DockPanel();
You would set the child of the PopUp to the DockPanel and then add children to the DockPanel.
Here is code that shows that:
var popup = new Popup();
var dockPanel = new DockPanel();
popup.Child = dockPanel;
dockPanel.Children.Add(new TextBox {Text = "First Child" });
popup.IsOpen = true;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With