如何在wpf vb.net中显示新窗口并隐藏窗口? [英] how to show new window and hide a window in wpf vb.net?

查看:87
本文介绍了如何在wpf vb.net中显示新窗口并隐藏窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。



我有主窗口有一个按钮。当我点击按钮它应该显示一个新的表格,但将保持在同一个窗口?我应该显示新窗口并隐藏上一个窗口还是有其他方法可以执行此操作?该应用程序已完全筛选,用vb.net编写。



谢谢。

Hi.

I have mainwindow that has a button. when I click the button it should show a new form but will remain at the same window? Should I show the new window and hide the previous one or there is another way to do this? the application is full screened, written in vb.net.

Thanks.

推荐答案

所有方法至少可以说,显示一个新窗口而不是主窗口是有问题的。您不能将新窗口设为主窗口。 (事实上​​你可以,但它也有问题,我们稍后再讨论它。)



首先,哪个窗口是main是由传递给的参数定义的 Application.Run(窗口)。您的方法的问题是您隐藏了主窗口。因此,当您关闭其他窗口时,应用程序实际上不会关闭。如果关闭主窗口,它可以关闭。要解决此问题,您需要覆盖虚拟方法 System.Windows.Window.OnClosed 以调用 Application.Shutdown 。它实际上取决于你想要什么。



我明白,当一种窗口取代另一种窗口时,你可能需要类似向导的行为。另一种方法是多次调用 Application.Run(Window),每次使用不同的窗口。通常,此代码是自动生成的。你需要删除主应用程序XAML并为应用程序的行为编写自己的入口点方法。



所有这些解决方法都可行,但是...



我认为它不会有多大意义。我认为最好的模式是只有一个窗口可用于所有应用程序。 (我不认为某些窗口可以用作模态对话框,你可以有一些。)你可以根据UI状态改变这种(总是主要)窗口的外观。让我们考虑类似向导的应用程序行为。它只是意味着你有一个不同窗口的行(列表),你可以在前进方向访问,有时可以向后移动。让我称那些顺序窗口为帧。它们通常共享一些按钮(和/或其他东西)。如果是这样,请执行以下操作:在(主)窗口上创建一个按钮面板和几个面板,每个面板代表一个框架。由于您一次只需要一个框架,所以隐藏所有这些面板,只有一个可见。使用您之前计划放置在单独窗口中的内容填充每个此类框架面板。现在,当您浏览帧序列时,隐藏除了给定步骤所需的所有帧之外的所有帧。



这很容易,会给你很多与单独的窗户一样少的问题。



-SA
All ways of showing a new window instead of the main one are questionable, to say the least. You cannot make a new window a main window. (In fact you can, but it is also problematic, let's talk about it later.)

First of all, which window is main is defined by the parameter passed to Application.Run(Window). The problem of your approach is that you have your main window hidden. So, when you close some other window, the application won't actually close. It can be closed if you close the main window. To work around it, you would need, for example, to override virtual the method System.Windows.Window.OnClosed to call Application.Shutdown. It actually depends on what you want.

I understand, you probably need wizard-like behavior, when one kind of window replace another one. Another way of doing so would be calling Application.Run(Window) several times, each time with different window. Normally, this code is auto-generated. You will need to remove main application XAML and write your own entry point method for such behavior of Application.

All such work-around approaches will work, but…

I don't think it would make a whole lot of sense. I think that the best pattern is to have only one window for all application. (I don't count some windows to be used as modal dialogs, you can have some.) You can change the appearance of such (always main) window depending on the UI state. Let's consider the wizard-like behavior of application. It simply mean that you have a line (list) of different "windows" which you can visit in forward direction and sometime go backward. Let me call those sequential windows "frames". They all usually share some buttons (and/or something else). If so, do the following: on your (main) window create, say, a panel for buttons and several panel each representing one frame. As you need only one frame at a time, make all those panels hidden and only one visible. Populate each of such frame panels with the content you planned earlier to be placed on a separate window. Now, as you navigate through the sequence of frames, hide all of them except the one which is needed on a given step.

This is easy and will give you much less problems as with separate windows.

—SA


这篇关于如何在wpf vb.net中显示新窗口并隐藏窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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