WPF打开新表单问题 [英] WPF Open New Form problem

查看:124
本文介绍了WPF打开新表单问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WPF表格,我使用C#;





我有一个名为MainWindow_1的窗口和另一个名为MainWindow_2的窗口,


MainWindow_1中的
我有一个按钮可以打开MainWindow_2。我的代码是:





A WPF Form, I use C#;


I have a window named "MainWindow_1" and another named"MainWindow_2",

in MainWindow_1 I have a button to open "MainWindow_2". My codes are:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using DevExpress.Xpf.Core;
using DevExpress.Xpf.Ribbon;
using DevExpress.Xpf.Bars;
using namespace.DXWPFApplication3;

namespace DXWPFApplication16 
 
{
    public partial class MainWindow_1 : DXRibbonWindow
    {
        public MainWindow_1()
        {
            InitializeComponent();

        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            

        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {

           MainWindow_2 win2 = new MainWindow_2.Show();
           win2.Show();
//I want this button opens another WPF form (which namespace DXWPFApplication3)//
            

        }

    }


}
();







但VS2012强调MainWindow_2 word.It说无法找到类型或名称空间



我该如何解决?



谢谢。




But VS2012, underlines "MainWindow_2" word.It says "Type or namespace couldn''t be found"

How can i solve it?

Thanks.

推荐答案

您需要将MainWindow_2所在的命名空间的引用添加到MainWindow_1的代码中。如果MainWindow_2在一个单独的程序集中,您可能也需要引用该程序集。



[OP已更新代码问题]

MainWindow_2 win2 = new MainWindow_2.Show()



应该是



MainWindow_2 win2 = new MainWindow_2() .Show()
You need to add a reference to the namespace that MainWindow_2 is in to the code for MainWindow_1. If MainWindow_2 is in a separate assembly, you may need to reference that assembly as well.

[OP has updated question with code]
MainWindow_2 win2 = new MainWindow_2.Show()

Should be

MainWindow_2 win2 = new MainWindow_2().Show()


只需按Ctrl +。在 MainWindow_2 中的行 MainWindow_2 win2 = new MainWindow_2();

它将解决你的名字空间(如果dll已经是项目的一部分)。
Just press Ctrl + . on MainWindow_2 in the line MainWindow_2 win2 = new MainWindow_2();
It will resolve your name space (if the dll is already part of the project).


这篇关于WPF打开新表单问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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