简体   繁体   English

在Windows之间传递参数

[英]Pass Parameters Between Windows

I have an application with a main window that loads in text file(s) and processes them. 我有一个带有主窗口的应用程序,可加载文本文件并对其进行处理。 Once the processing is done, it creates a list of network switch objects. 处理完成后,它将创建网络交换机对象的列表。 I can then perform various checks and queries on the data. 然后,我可以对数据执行各种检查和查询。 These checks or queries use child windows. 这些检查或查询使用子窗口。 I have been passing the list of switches - here's an example of a child window where I modified the constructor to take my list of switches. 我一直在传递开关列表-这是一个子窗口的示例,我在其中修改了构造函数以获取开关列表。 I am wondering if this is a bad design or if there is a way to link the child window to the data in the list without having to pass it in. The next major step in this project is going to be a GUI front-end to browse all the data I am parsing out, rather than just run reports. 我想知道这是不是一个错误的设计,或者是否有一种方法可以将子窗口链接到列表中的数据而不必传递它。该项目的下一个主要步骤将是GUI前端浏览我正在解析的所有数据,而不只是运行报告。 So I want to learn to do it the right way now. 所以我现在想学习正确的方法。

 public partial class LogFileWindow : Window
{
    private ObservableCollection<LogFileEntry> _LogFileCollection = new ObservableCollection<LogFileEntry>();

    private List<CiscoSwitch> SwitchList = new List<CiscoSwitch>();

     // constructor modified to accept a list as a paramter
    public LogFileWindow(List<CiscoSwitch> sl)
    {
        SwitchList = sl;
        InitializeComponent();
    } 

..... } .....}

Just have a look at the wpf MVVM model, like Kent already mentioned. 就像看看Kent一样,看看wpf MVVM模型。 A very good starting point is this post on MSDN: http://social.msdn.microsoft.com/Forums/pl/wpf/thread/b8922be3-e73c-4d90-9bc6-172421fb6b1c 一个很好的起点是MSDN上的这篇文章: http : //social.msdn.microsoft.com/Forums/pl/wpf/thread/b8922be3-e73c-4d90-9bc6-172421fb6b1c

Greetings, 问候,

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

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