从主页访问方法 [英] Accessing a method from Mainpage

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

问题描述

我正在尝试从另一个页面访问主页上的方法.主页方法是公开".调用它时,出现错误对象引用未设置为对象的实例".从主页上可以正常使用!! :confused:

I''m trying to access a method on my mainpage from another page. The mainpage method is "public". when I call it, I get an error "object reference not set to an instance of an object." It works fine from mainpage!! :confused:

推荐答案

您要从一页导航到另一页吗?如果真是这样,那么您不能直接做.您必须创建MainPage的实例,然后可以调用公共方法:

Are you navigating from one page to another? If that is the case, then you can''t directly do. You have to create the instance of the MainPage and then you can call the public method:

MainPage mainPage = new MainPage();<br />
mainPage.DoCall();<br />



如果您的主页仍作为基本页面加载到内存中,则&如果要加载任何UserControl,则还可以从实例轻松访问它.

如果这可以解决您的问题,请标记为答案",如果您正在使用其他机制从另一页面加载一页,请进行详细说明.我们会更轻松地为您提供帮助.

感谢您在CodeProject中发布.



If your mainpage is still loaded in memory as the base page & on top of it if you are loading any UserControl then you can easily access it from the instance.

If this solves your problem, please "Mark As Answer", and if you are using some other mechanism to load one page from another, please elaborate the same. It will be easier for us to help you out.

Thank you for posting in CodeProject.


您需要在此处发布一些代码-主页中的某些对象可能为null,并且如果有人在看代码,他们可能会给出您一个解决方案.
You need to post some code here - some object in your main page might be null and if someone here looks at the code, they might be able to give you a solution.


您如何访问MainPage的主实例?我怀疑它设置为null.
How are you accessing the main instance of MainPage? I suspect it is set to null.


这篇关于从主页访问方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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