我正在使用 MVVM 模型创建应用程序。我的应用程序是具有 2 个全景项目模板的全景应用程序。
我已经创建了一个视图、视图模型和模型文件夹,并且在这些文件夹中分别有Item.xaml
和Item1ViewModel.cs
、Item2ViewModel
和Item1Model.cs
、文件。Item2Model.cs
在视图中,Item.xaml
我有以下控件:
当用户单击 PanoramaItem1 页面中的“GetDetails”按钮时,我将在页面中显示、ReadOperationStatus
和DateOfRegistration
、PointsEarned
的LastTimePlayed
值。Name
PanoramaItem2
<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 吗?
任何有关代码的帮助将不胜感激