我需要创建一些项目并将其添加到弹出代码隐藏中。在 XAML 中很容易做到这一点:
<Popup StaysOpen="False">
<DockPanel>
//Items here
</DockPanel>
</Popup>
我认为“子项”是我需要添加我的项目的地方,但我没有在其中看到任何“添加”、“项目”、“源”或“内容”。有谁知道怎么做?
Popup myPopup= new Popup();
myPopup.Child // ... need to add items there
最佳答案
Popup 是一个 FrameworkElement,只能有一个子元素 (Child) => 你不能在里面添加多个控件,但是你可以设置 Child 成为你想要的任何 UIElement。例如一个 DockPanel,然后使用面板上的 AddChild 来添加更多控件。
myPopup.Child = new DockPanel();
关于c# - 以编程方式将项目添加到弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18163096/