简体   繁体   English

主窗口中的WPF视图

[英]WPF Views in main window

I have created a new WPF Application using Visual Studio 2010 so I have a default MainWindow.xaml , I have created a folder 'Views' which holds a couple of xaml pages that are different views for my app. 我使用Visual Studio 2010创建了一个新的WPF应用程序,所以我有一个默认的MainWindow.xaml ,我创建了一个文件夹“ Views”,其中包含几个xaml页面,这些页面与我的应用程序的视图不同。

What I want to do is to have these views in the MainWindow.xaml and transition between them at certain time intervals. 我想要做的是将这些视图保存在MainWindow.xaml中,并以一定的时间间隔在它们之间进行转换。 Could anyone give me an idea on how to achieve this? 谁能给我一个关于如何实现这一目标的想法?

Thanks! 谢谢!

You need to define how child forms will be displayed inside your MainWindow, there are several ready made solutions for this problem, check-out these links: 您需要定义子窗体在MainWindow中的显示方式,针对此问题有几种现成的解决方案,请查看以下链接:

For a simple scenario (without any complications or etc), you would do the same as you would do with a parent object composing a set of child objects. 对于简单的情况(没有任何复杂性等),您将执行与由一组子对象组成的父对象相同的操作。

Class A{
private View FirstView;
private View SecondView;

...

}

then you would want to visually place it inside your UI hierarchy as in a child of a Grid or a Canvas for an instance. 那么您可能希望将其可视化地放置在UI层次结构内,就像在实例的Grid或Canvas的子级中一样。

For a better use, try DI or IoC container in order not be worried about creating the object and keeping references. 为了更好地使用,请尝试使用DI或IoC容器,以免担心创建对象和保留引用。

http://code.google.com/p/autofac/ http://code.google.com/p/autofac/

You might also want to think about the communication between your Views and Window. 您可能还需要考虑视图和窗口之间的通信。 For that, please have a look at EventAggregator implementations 为此,请查看EventAggregator实现

https://stackoverflow.com/questions/2343980/event-aggregator-implementation-sample-best-practices https://stackoverflow.com/questions/2343980/event-aggregator-implementation-sample-best-practices

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

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