如何将数据从CustomMessageBox传递到调用它的页面?

问题描述 投票:0回答:4

我有一个页面,在那里我调用了一个 xaml布局页 作为一个显示国家列表的CustomMessageBox,我是借助LongListSelector来显示国家列表的。我在LongListSelector的帮助下显示国家列表。在选择国家后,我只是想关闭CustomMessageBox,并带着选择的国家回到调用这个CustomMessageBox的页面。如何实现这一点呢?这里是下面的代码片段。

FirstPage :

  CountrySelectionDialog countrySelectedDialog = new CountrySelectionDialog();
  CustomMessageBox cmd = new CustomMessageBox()
  {
        Content = countrySelectedDialog,
        Opacity = 0.9
  };

SecondPage即CountrySelectionDialog页面。

  private void on_Country_Selection(object sender, SelectionChangedEventArgs e)
    {
        if(e.AddedItems.Count>0)
        {
            country = e.AddedItems[0] as Country;
             // Now how to go back with selected country to the original page?

        }
    }
c# windows-phone-8
4个回答
0
投票

在长列表选择器的选择变化事件中使用这个代码。

LLs_SelectionChange(....) 
{
String s= lls.SelectedItem;
MessageBox.close();
NavigationService.Navigate(new Uri("/YourPage.xaml?country="+s),UriKind.RelativeorAbsolute);
}

在你的页面中使用查询字符串获取国家。


0
投票

使用 IsolatedStorageSettings

例子

IsolatedStorageSettings userSettings=IsolatedStorageSettings.ApplicationSettings;
userSettings["Country"]=country;
userSettings.Save();

在得到国家后添加这个,然后添加 NavigationService.GoBack() 而在你想要的国家值的地方,使用下面的代码检查国家是否被存储在仓库中

if(userSettings.ContainsKey("Country")
{
    country=userSettings["Country"];
}

如果国家是字符串,上面的功能就会生效,如果是对象,你可以使用 电话应用服务 来保存国家值,然后返回导航并检查PhoneApplicationService是否含有 Country 对象。


0
投票

我使用了以下链接 如何用编程方式创建一个LongListSelector控件。 我没有创建一个单独的文件作为CustomMessageBox,而是以编程的方式创建了自己的xaml文件,并在CustomMessageBox中调用它。


0
投票

检查这个。

private void on_Country_Selection(object sender, SelectionChangedEventArgs e)
    {
        if(e.AddedItems.Count>0)
        {
            country = e.AddedItems[0] as Country;
            PhoneApplicationService.Current.State("COUNTRY") = country;
               //close the page



        }
    }

现在可以在任何地方检索国家代码。

String countrycode  = PhoneApplicationService.Current.State("COUNTRY");
© www.soinside.com 2019 - 2024. All rights reserved.