[英]public variables wp7 mango
hi i need to use a variables from page to show in another page at text block in windows phone 7. i got a problem that the second page doesn't declare the variables: here's a part of my code: 嗨我需要使用页面中的变量来显示在Windows Phone 7中的文本块中的另一个页面。我遇到了第二页没有声明变量的问题:这是我的代码的一部分:
public static class MainPage : PhoneApplicationPage
{
string result;//var i wanna use at the all application pages
string status;//var i wanna use at the all application pages
string userId;//var i wanna use at the all application pages
string msg;//var i wanna use at the all application pages
WebClient client;
// Constructor
public MainPage()
{
InitializeComponent();
client = new WebClient();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
}
}
///second page
public partial class info : PhoneApplicationPage
{
public info()
{
InitializeComponent();
textBlock1.Text = result.value();
}
}
but this code dosent work ny help?? 但这段代码有用吗?
but this code dosent work
但是这段代码很有用
Because your variables are private and their scope is limited to the MainPage
class. 因为您的变量是私有的,并且它们的范围仅限于
MainPage
类。
If you want them to be public, you have to add the public
keyword. 如果您希望它们是公开的,则必须添加
public
关键字。
Better: you should use properties instead: 更好:你应该使用属性:
public string Result { get; set; }
Also, you can't write a global variable . 此外,您不能编写全局变量 。 As C# is an object-oriented programming language, you'll have to use an instance of your
MainPage
class to access to your properties: 由于C#是面向对象的编程语言,因此您必须使用
MainPage
类的实例来访问您的属性:
MainPage myPage = new MainPage();
....
textBlock1.Text = myPage.Result;
Another thing: you're using variables/properties, not functions. 另一件事:你使用变量/属性,而不是函数。 So you can't write
result.value();
所以你不能写
result.value();
. 。 Use
result.value;
使用
result.value;
instead. 代替。
I suggest you to have a look at this MSDN article about properties. 我建议你看看这篇关于属性的MSDN文章 。
据我所知,您需要在MainPage类范围之外声明结果变量或添加public关键字
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.