Download the Windows Azure SDK and Tools - To do these posts, absolutely necessary
This post will focus on the data model used by this type of application. We need to understand how data is modeled if we plan to architect a cloud-based back-end. The next few screens will talk a lot about SampleDataGroup and SampleDataItem objects. These are the core data objects used by a Windows 8 Metro Grid Application.
public
abstract
class
BindableBase : INotifyPropertyChanged
{
/// <SUMMARY>
/// Multicast event for property change notifications.
/// </SUMMARY>
event
PropertyChangedEventHandler PropertyChanged;
/// Checks if a property already matches a desired value. Sets the property and
/// notifies listeners only when necessary.
/// <TYPEPARAM name="T">Type of the property.</TYPEPARAM>
/// <PARAM name="storage">Reference to a property with both getter and setter.</PARAM>
/// <PARAM name="value">Desired value for the property.</PARAM>
/// <PARAM name="propertyName">Name of the property used to notify listeners. This
/// value is optional and can be provided automatically when invoked from compilers that
/// support CallerMemberName.</PARAM>
/// <RETURNS>True if the value was changed, false if the existing value matched the
/// desired value.</RETURNS>
protected
bool
SetProperty<T>(
ref
T storage, T value, [CallerMemberName] String propertyName =
null
)
if
(
object
.Equals(storage, value))
return
false
;
storage = value;
this
.OnPropertyChanged(propertyName);
true
}
/// Notifies listeners that a property value has changed.
/// value is optional and can be provided automatically when invoked from compilers
/// that support <SEE cref="CallerMemberNameAttribute" />.</PARAM>
void
OnPropertyChanged([CallerMemberName]
string
propertyName =
var eventHandler =
.PropertyChanged;
(eventHandler !=
eventHandler(
,
new
PropertyChangedEventArgs(propertyName));
SampleDataSource()
String ITEM_CONTENT = String.Format(
"Item Content: {0}\n\n{0}\n\n{0}\n\n{0}\n\n{0}\n\n{0}\n\n{0}"
"Curabitur class ..."
);
var group1 =
SampleDataGroup(
"Group-1"
"Group Title: 1"
"Group Subtitle: 1"
"Assets/DarkGray.png"
"Group Description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus tempor scelerisque lorem in vehicula. Aliquam tincidunt, lacus ut sagittis tristique, turpis massa volutpat augue, eu rutrum ligula ante a ante"
group1.Items.Add(
SampleDataItem(
"Group-1-Item-1"
"Item Title: 1"
"Item Subtitle: 1"
"Assets/LightGray.png"
"Item Description: Pellentesque porta, mauris quis interdum vehicula, urna sapien ultrices velit, nec venenatis dui odio in augue. Cras posuere, enim a cursus convallis, neque turpis malesuada erat, ut adipiscing neque tortor ac erat."
ITEM_CONTENT,
group1));
.AllGroups.Add(group1);
// Repeat for all groups. here is for Group 2
var group2 =
"Group-2"
"Group Title: 2"
"Group Subtitle: 2"
"Group Description: Lorem "
group2.Items.Add(
"Group-2-Item-1"
"Item Description: Pellentesque porta, "
group2));
.AllGroups.Add(group2);
// Omitted for brevity
[Windows.Foundation.Metadata.WebHostHidden]
SampleDataCommon : FastMotorcycle.Common.BindableBase
private
static
Uri _baseUri =
Uri(
"ms-appx:///"
SampleDataCommon(String uniqueId, String title, String subtitle, String imagePath, String description)
._uniqueId = uniqueId;
._title = title;
._subtitle = subtitle;
._description = description;
._imagePath = imagePath;
_uniqueId =
.Empty;
UniqueId
get
._uniqueId; }
set
.SetProperty(
._uniqueId, value); }
_title =
Title
._title; }
._title, value); }
_subtitle =
Subtitle
._subtitle; }
._subtitle, value); }
_description =
Description
._description; }
._description, value); }
ImageSource _image =
String _imagePath =
ImageSource Image
._image ==
&&
._imagePath !=
._image =
BitmapImage(
Uri(SampleDataCommon._baseUri,
._imagePath));
._image;
._imagePath =
._image, value);
SetImage(String path)
._imagePath = path;
.OnPropertyChanged(
"Image"
SampleDataGroup : SampleDataCommon
SampleDataGroup(String uniqueId, String title, String subtitle, String imagePath, String description)
:
base
(uniqueId, title, subtitle, imagePath, description)
ObservableCollection<SAMPLEDATAITEM> _items =
ObservableCollection<SAMPLEDATAITEM>();
ObservableCollection<SAMPLEDATAITEM> Items
._items; }
IEnumerable<SAMPLEDATAITEM> TopItems
// Provides a subset of the full items collection to bind to from a GroupedItemsPage
// for two reasons: GridView will not virtualize large items collections, and it
// improves the user experience when browsing through groups with large numbers of
// items.
//
// A maximum of 12 items are displayed because it results in filled grid columns
// whether there are 1, 2, 3, 4, or 6 rows displayed
._items.Take(12); }
SampleDataItem : SampleDataCommon
SampleDataItem(String uniqueId, String title, String subtitle, String imagePath, String description, String content, SampleDataGroup group)
._content = content;
._group = group;
_content =
Content
._content; }
._content, value); }
SampleDataGroup _group;
SampleDataGroup Group
._group; }
._group, value); }