【发布时间】:2013-11-21 05:13:32
【问题描述】:
我正在使用 MVVM 模型创建应用程序。我的应用程序是具有 2 个全景项模板的全景应用程序。
我已经创建了一个视图、视图模型和模型文件夹,并且在这些文件夹中分别有 Item.xaml 和 Item1ViewModel.cs,Item2ViewModel 和 Item1Model.cs,Item2Model.cs 文件。
在 veiw Item.xaml 我有以下控件:
当用户单击 PanoramaItem1 页面中的“GetDetails”按钮时,我将在PanoramaItem2 页面中显示ReadOperationStatus、DateOfRegistration 和PointsEarned、LastTimePlayed、Name 的值。
<phone:PhoneApplicationPage>
<Grid x:Name="LayoutRoot">
<phone:Panorama Title="AccountDetails">
<!--Panorama item one-->
<phone:PanoramaItem Header="item1">
<Grid>
<TextBox Text="{Binding EmailId}"></TextBox>
<TextBox Text="{Binding MobileNumber}"></TextBox>
<Button Content="GetDetails" Command="{Binding GetDetailsClickCommand}"></Button>
<TextBlock text="{Binding ReadOperationStatus}"/>
<TextBlock text="{Binding DateOFRegistration}"/>
</Grid>
</phone:PanoramaItem>
<!--Panorama item two-->
<phone:PanoramaItem Header="item2">
<Grid>
<TextBlock Text="{Binding PointsEarned}"></TextBlock>
<TextBlock Text="{Binding LastTimePlayed}"></TextBlock>
<TextBlock Text="{Binding Name}"></TextBlock>
</Grid>
</phone:PanoramaItem>
</phone:Panorama>
</Grid>
</phone:PhoneApplicationPage>
我的模型类中有以下代码:
public class Item1Model
{
public Item1Model()
{
}
public string EmailID { get; set; }
public int MobileNumber { get; set; }
public string REadOperationStatus{ get; set; }
public DateTime DateOfRegistration { get; set; }
}
public class Item2Model
{
public Item2Model()
{
}
public int PointsEarned { get; set; }
public DateTime LastPlayed { get; set; }
public string Name { get; set; }
}
ViewModel 的代码如下:
class Item1ViewModel:InotifyPropertyChanged
{
public Item1ViewModel()
{
}
public System.Windows.Input.ICommand GetDetailsClickCommand
{
get
{
return new DelegateCommand((o) =>
{
Task.Factory.StartNew(() =>
{
GetPlayerDetails();
});
});
}
}
public static GetPlayerDetails()
{
//i want to access EmailID,MobileNumber which are inputs to the service method
//here i connect to a service and wait for the event DetailsDownload_Completed.
}
private void DetailsDownload_Completed(DetailsOwner sender, EventArgs args)
{
//here i get args.PointsEarned, args.LAstPlayed,args.Name ,
//which i want to bind them to the respective peroperties in the panoramaitem1,panoramaitem2
}
}
class Item2ViewModel
{
public Item2ViewModel ()
{
//currently i dont have anything here
}
}
the questions I have is how do I read the values of EMail, Mobilenumber which user has enterd in UI. And how do I set the values back in UI once I read the values from service..I want to know how should the binding be here..
我还需要在模型中实现 INotifyPropertyChanged 吗?
非常感谢您对代码的任何帮助
【问题讨论】:
标签: c# windows-phone-7 mvvm windows-phone-8 mvvm-light