private void Button_Click(object sender, RoutedEventArgs e)
{
Button click_bt = sender as Button;
string tag01 = click_bt.Tag as string;
if (tag01=="") {
MessageBox.Show("跳转为空");
}
else
{
bool openwind = false;
foreach (Window window in Application.Current.Windows)
{
if (window.GetType().Name == tag01)//使用窗体类进行匹配查找
{
openwind = true;
string item01 = window.ToString();
Console.WriteLine("窗口已打开{0}",item01);
}
}
if (openwind == false) {
Type type01 = this.GetType();
Assembly assembly01 = type01.Assembly;
Window win01 = assembly01.CreateInstance(type01.Namespace + "." + click_bt.Tag) as Window;
if(win01 == null) {
MessageBox.Show("跳转窗口不存在!");
}
else
{
win01.Show();
}
}
}
}
WPF C# 获取已打开窗口
最新推荐文章于 2024-07-25 16:02:00 发布