How to add another person’s window in WPF?
To add another person’s window, you can use the Window object in WPF. Here are the steps to add another person’s window:
- Firstly, you need to add other people’s form class to your project. You can directly add the other people’s form class files to the project, or add them as a reference to the project.
- Create a new Window object in your WPF form to host other forms.
- Instantiate the form class of the other person at the position where additional people are needed and assign it to the Content property of the newly created Window object.
- Invoke the Show method of the newly created Window object to display someone else’s form.
Here is a sample code demonstrating how to add someone else’s form.
using System.Windows;
namespace YourNamespace
{
public partial class YourMainWindow : Window
{
public YourMainWindow()
{
InitializeComponent();
// 创建一个新的Window对象
Window otherPersonWindow = new Window();
// 实例化其他人的窗体类
OtherPersonWindowClass otherPersonWindowClass = new OtherPersonWindowClass();
// 将其他人的窗体赋值给新创建的Window对象的Content属性
otherPersonWindow.Content = otherPersonWindowClass;
// 显示其他人的窗体
otherPersonWindow.Show();
}
}
}
Please note that the above example assumes OtherPersonWindowClass is the window class of another person. You need to replace YourNamespace, YourMainWindow, and OtherPersonWindowClass with the actual names as per your situation.