简体   繁体   English

WPF:通过实现带有导航窗口的选项卡来维护状态?

[英]WPF: Maintaining states by implementing tabs with navigation windows?

I'm making an application in C# WPF that consists of a top-root NavigationWindow with several pages that I navigate between for the purpose of the project. 我正在C#WPF中制作一个应用程序,该应用程序由一个具有多个页面的上层NavigationWindow组成,出于项目目的,我可以在多个页面之间进行导航。 At this point, I want to extend the functionality of the application by adding in a second "state" of the program. 在这一点上,我想通过添加程序的第二个“状态”来扩展应用程序的功能。

Here's how I'd like this to work: Essentially the program is a data collection application. 这就是我希望的工作方式:本质上,该程序是一个数据收集应用程序。 At the moment it displays relevant UI information for database A and allows you to collect data for that one specifically. 目前,它显示数据库A的相关UI信息,并允许您专门为该数据库收集数据。 I want to expand the software by adding in a second set of UI elements that collect different data for database B, and I want to navigate between them using Tabs at the top (so using tabcontrol and tabitems). 我想通过添加第二组UI元素来扩展软件,这些元素为数据库B收集不同的数据,并且我想使用顶部的Tabs(以便使用tabcontrol和tabitems)在它们之间进行导航。

The part that I'm stuck on is the maintaining states portion: For example, if I'm on the tab for database A, I can go through a date selection screen and to the actual collection screen, but if I click on the tab for database B, then it will still be back at the date selection screen since I have not done anything there yet (essentially like having 2 programs running at the same time, within each tab). 我停留的部分是维护状态部分:例如,如果我在数据库A的选项卡上,则可以通过日期选择屏幕转到实际的收集屏幕,但是如果单击该选项卡,数据库B,那么它仍然会回到日期选择画面,因为我没有做任何事情存在,但(实际上就像有两个程序同时运行,每个标签内)。

I tried seeing if I could change the root element of the software from a NavigationWindow to a Page that contains a NavigationWindow inside of tabitems (since only Page implements tabcontrol), but I have not figured out how to do this (if it can even be done). 我尝试查看是否可以将软件的根元素从NavigationWindow更改为包含在tabitems内的NavigationWindow的页面(因为只有Page实现了tabcontrol),但是我还没有弄清楚该怎么做(如果可以的话)完成)。 Is there a better way to go about doing this? 有没有更好的方法可以做到这一点?

There are two ways I see to do this: 我看到有两种方法可以做到这一点:

  1. Keep the State information outside of the tab's Content. 将州信息保留在选项卡的内容之外。 So items such as CurrentStep would be tracked at a higher level than the TabControl's content 因此,诸如CurrentStep之类的项目将在高于TabControl内容的级别上被跟踪

  2. Or make a fake tab control. 或制作假的Tab控件。 Switching tabs doesn't really change anything, instead it just changes a property in your ViewModel that determines the connection. 切换选项卡并没有真正改变任何东西,相反,它只是改变了ViewModel中确定连接的属性。

As a side note, why not consider a dropdown to specify the database instead of a tab control? 附带说明一下,为什么不考虑使用下拉列表指定数据库而不是使用制表符控件?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM