English 中文(简体)
打开新窗口,但并不总是新窗口。
原标题:Open a new window, but not always a new instance of it

如果你把这看作是一个 question问题,那么我仍然处在 c的学习阶段。

在该项目中,我有主要窗口和一个称为“窗口1”的新窗口。

在主线上,我有一个县,它就象窗口1那样:

private void Button_Click(object sender, RoutedEventArgs e)
{

    Window1 W1 = new Window1();
    W1.Show();
    this.Close();

}

现在,这项工作按预期进行,创造了新的窗口1,并在关闭主窗时展示。

但这里的捕获量是:在窗口1中,有些 st子可能改变,就像用户点击的纽顿一样,然后当新显示时,纽芬兰藏匿。

我还在窗口1上打了背顿语,使用与上述相同的代码回馈主寡妇(现为新的窗口1,但新主窗口)。

But at this point, when I click in main, on the button again to go to window1, that window1 is back to default state. Seems logical to me because it creates a new instance when using the button.

但是,如果我想再次打开窗口1的首例,即用户已经改变的窗口,那么我怎么办?

首先,我想将<条码>Window1 W1 = 新的窗口1(a);置于纽伦方法之外,但这也因为“背”纽扣而赢得了t工作。

我希望我能充分解释我想要做的事情。

任何想法都是这样?

====================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

EDIT:

using the code example from "chrfin" some parts genarate errors, like the "visible = true" part maybe this is because i use express 2010 or it is because i use WPF and not forms?

in the main:

Window1 W1 = null; // Initialise Field.  

private void CalcTabel_Click(object sender, RoutedEventArgs e)
{

    if (W1 == null)
    {
        W1 = new Window1();
        W1.MainWindow = this; //ERROR 
        W1.Show();
    }
    else
        W1.Visibility = Visibility.Visible;
    this.Visibility = Visibility.Hidden;
}

页: 1

public MainWindow w1 { get; set; }

private void Quit_Click(object sender, RoutedEventArgs e)
{
    w1.Visibility = Visibility.Visible;
    this.Visibility = Visibility.Hidden;

}

now the error that i get on the main part is: WpfApplication1.Window1 does not contain a definition for MainWindow accepting a first argument of type WpfApplication1.Window1 could be found(are you missing a using directive or an assembly reference?)

仅仅删除这一错误线,就会造成结果,使部分人无法得到任何东西。

any ideas ?

====================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

EDIT:

Thanx again "chrfin" got it working now :)

主要内容是:

Window1 W1 = null; // Initialise Field.  

private void CalcTabel_Click(object sender, RoutedEventArgs e)
{

    if (W1 == null)
    {
        W1 = new Window1();
        W1.Hoofdmenu = this;
        W1.Show();
    }
    else
        W1.Visibility = Visibility.Visible;
    this.Visibility = Visibility.Hidden;
}

:

public MainWindow Hoofdmenu { get; set; }

private void Quit_Click(object sender, RoutedEventArgs e)
{

    Hoofdmenu.Visibility = Visibility.Visible;
    this.Visibility = Visibility.Hidden;

}
  • Solved -
最佳回答

你可以这样做:

Window1 w1 = null;

private void Button_Click(object sender, RoutedEventArgs e)
{
    if(w1 == null)
    {
        w1 = new Window1();
        w1.MainWindow = this; //create this property - see below
        w1.Show();
    }
    else
        w1.Visible = true;

    this.Visible = false;
}

以及

public MainWindow MainWindow { get; set; }    

private void ButtonBack_Click(object sender, RoutedEventArgs e)
{
    this.Visible = false;
    MainWindow.Visible = true;
}
问题回答

实现预期结果有许多途径。 我使用的方法如下:

Window1 W1 = null; // Initialise Field. 

private void Button_Click(object sender, RoutedEventArgs e)
{
    if (W1 == null) W1 = new Window1();
    W1.Show();
    this.Close();
}

你也可以取消这项活动。

这里可以有一个以上解决办法。

(1) 您可以保留Windows1用户所做的改动。 每当你重新启用“温得”1 时,就会通过环境变化或以往的变化,使“温得”1 能够根据最后一个国家重新调整自己。

2) 不是总是制造一个窗口的新例子,而是把窗户关闭在 but子上,只是显示和隐藏,使窗口1在用户的可见和看不到

Make a static property to store the reference of W1 in it and in Button_Click method check if it has some value use it otherwise create a new one;

另一种选择是,通过<代码>申请查阅申请标本中的开放窗口。 当前,Windows 。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签