如何使用从mainpage.xaml.cs到anotherpage.xamm.cs的字符串
本文关键字:cs anotherpage xamm 字符串 mainpage xaml 何使用 | 更新日期: 2023-09-27 18:01:12
我从昨天开始就在寻找解决方案,但如果有人能帮我的话,我还没有找到。
所以现在,我有:在主页.xam中:2个文本框TextBox Name="id">和TextBox Name="compte">
我从mainpage.xaml.cs中的2个文本框中获得字符串,我正在执行=>
主页.xaml.cs
public string url()
{
string url_ = (myCompte() + myId());
return url_;
}
mycompte
和myid
是返回我的文本框的字符串内容的公共字符串函数。
我需要在C#的另一个页面中使用url_
,但我不知道如何使用。
ClassicView.xaml.cs
private void loadJson()
{
string i = url();
MessageBox.Show(i);
WebClient webClient = new WebClient();
webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
webClient.DownloadStringAsync(new Uri(i));
}
它告诉我这里不存在url。也许你可以帮我。
对我来说,如何在更多窗口之间进行通信的最佳解决方案是通过信使。我更喜欢信使MVVM轻工具包。从MainPage.xaml.cs,您可以使用此url发送消息,并在ClassicView.xaml.cs中注册接收消息以处理您的消息。尝试阅读它,例如在MVVM Light Toolkit消息传递示例
您可以将URL定义为静态字段,并从其他页面访问它。