如何从嵌套类中调用主页? [英] How to Call the mainpage from within a nested Class?

查看:83
本文介绍了如何从嵌套类中调用主页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在不创建Silverlight应用程序的主页的情况下调用它.

可以说,我有一个按下按钮然后创建一个名为daMaster的类的形式,daMaster执行一个调用另一个称为dams的类的方法.

然后,dams执行要更改MainPage上标签的方法.

如果我使用MainPage mp = new MainPage();,如果我错了,请更正我,但是这样做不会创建页面的新实例还是会检索(我怀疑)?

I would like to know how to call the Main page of the Silverlight application without creating one.

Lets say I have the form it presses a button then create a class called daMaster and daMaster executes a method that calls another class called dams.

Then dams executes a method that wants to change a label on the MainPage.

If I use MainPage mp = new MainPage();, correct me if I''m wrong but does that not create a new instance of the page or does it retrieve(which i doubt)?

推荐答案

线索在词中:

MainPage mp = MainPage();

有很多方法可以做到这一点,但是最好的办法是让您的类抛出一个事件,它的父母可以订阅该事件,并抛出它自己的事件以将其传递给表单.这样,表单仅在 it 希望更改其标签的情况下才预订该事件,并且该表单位于正确的线程上-您的类对此一无所知.最重要的是,您的班不必知道上面的两个班中的任何一个.除非您的设计中有错误,否则绝对不需要了解表单.
The clue is in the word:

MainPage mp = new MainPage();

There are a number of ways to do this, but the best is to have your class throw an event, which it''s parent can subscribe to, and throw it''s own to pass it up to the form. That way, the form only subscribes to the event if it wants it''s label changed, and is on the correct thread - which your class has no idea about. Best of all, your class does not have to know about either of the two classes above it. It definitely does not need to know about forms, unless there is something very wrong in your design.


这篇关于如何从嵌套类中调用主页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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