WPF:如何动态地添加控件中动态创建的WPF窗口 [英] WPF: How to dynamically Add Controls in dynamically created WPF Window

查看:1350
本文介绍了WPF:如何动态地添加控件中动态创建的WPF窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的C#项目添加一个WPF输入框。我在C#有一个WinForm一个来自输入框,但它有WinForm的外观和感觉。于是我就在WPF重新创建它。我创建的所有控件(标签,按钮,文本框),但我无法将它们添加到我的窗口。

I want to add a WPF Input Box in my Project in C#. I got a WinForm one from InputBox in C# but it has Winform look and feel. So i was recreating it in WPF. I have created all the controls (Label, Button, Textbox) but i am unable to add them to my window.

我的窗口是由它的ShowDialog方法

My window is a window variable called by its ShowDialog Method

static Window winInputDialog

窗口通过ShowDialog的,但没有控制显示。请帮助。

The Window is showing through ShowDialog but without controls. Please help.

推荐答案

有两种方式来帮助你在窗口控件:

There are two ways to get controls in your window:


  1. 请总体设计东西在VisualStudio中的设计师

  2. 由code添加控件。下面是创建一个窗口,并把控制它的简短,简单的示例:

  1. Do the whole designing stuff in the Designer of VisualStudio
  2. Add the controls by code. Here is a short, simple sample of creating a window and putting controls in it:

var window = new Window();
var stackPanel = new StackPanel { Orientation = Orientation.Vertical };
stackPanel.Children.Add(new Label { Content = "Label" });
stackPanel.Children.Add(new Button { Content = "Button" });
window.Content = stackPanel;


这篇关于WPF:如何动态地添加控件中动态创建的WPF窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆