WPF C# 获取已打开窗口

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();
            }
               
          
        }


    }
    



  


}

  • 6
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值