在windows phone中,不同页面间传值是用以下代码就可以了
PhoneApplicationService.Current.State[“strKey”]
我自己封装的代码:
TripDealer.cs:
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Shell;
namespace lifeCircle.Classes
{
public class TripDealer
{
private const string tripKey = "trip";
public TripInfo CurrentTrip
{
get
{
if (!PhoneApplicationService.Current.State.ContainsKey(tripKey))
{
return null;
}
else
{
return PhoneApplicationService.Current.State[tripKey] as TripInfo;
}
}
set { PhoneApplicationService.Current.State[tripKey] = value; }
}
}
}
consuming Code:
using lifeCircle.Classes;
TripDealer objDealer = new TripDealer();
if (null == objDealer.CurrentTrip)
{
tbDate.Text = DateTime.Now.ToString("yyyy-MM-dd");
}
if (null == objDealer.CurrentTrip)
{
objDealer.CurrentTrip = new TripInfo();
}
objDealer.CurrentTrip.Name = tbTripName.Text;
objDealer.CurrentTrip.TripDate = DateTime.Parse(tbDate.Text);
objDealer.CurrentTrip.MemberList = tbMembers.Text;
NavigationService.Navigate(new Uri("/Pages/TripEditSecond.xaml",UriKind.Relative));