Original address: http://channel9.msdn.com/Series/Windows-Phone-8-Development-for-Absolute-Beginners/ Part-12-improving-the-view-model-and-sample-data
Series Address:http://channel9.msdn.com/Series/Windows-Phone-8-Development-for-Absolute-Beginners
Source code: HTTP://AKA.MS/ABSBEGINNERDEVWP8
PDF version:http://aka.ms/absbeginnerdevwp8pdf
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/
We've done our basic work, and next we'll focus on the core of the application: the data model. This requires that we transform the entity model of the previous lesson into a viable data model that can represent the hierarchical structure between data and data.
Here are our plans for this lesson:
We will briefly analyze our requirements (the entity model is all we have today) and quickly map out the data model that will be implemented in the application.
We will implement the data model in code.
We will create the data in an XML file to display it in the mainpage XAML designer at design time.
Modifies the MainPage.xaml binding expression to point to instances and properties of classes in the data model.
1. Analyze the entity model and design the data model
After viewing the entity model and thinking about how to optimally delegate tasks to different classes, I designed a basic class model with the data structure of the application class model as follows:
The Soundmodel class contains references to groups of five sounds in your application. Please note that these properties are soundgroup types.
The Soundgroup class represents the view or type that I referred to earlier. I've been looking for a correct term to describe it, but in essence it's a grouping rather than a view or type. (The View only indicates the visual effects of the tiles used to display the sound, and the type is.) NET has a special connotation) Soundgroup has a title (it is used in the MainPage.xaml pivot control as the PivotItem caption) and a sounddata generic collection.
The Sounddata class represents the sound itself. Each Sounddata instance will contain a title, and clicking the title will play the sound associated with Sounddata, which is stored in the Sounddata filepath attribute.
Then we will implement the function in the diagram through the code and there will be some additions in the process of implementation.
2. Create a new data model class for your application
Based on our plans and data model diagrams, we will implement this new data model.
Right-click the ViewModels folder and choose Add | new item: