/// <summary> /// Initializes a new instance of the <see cref="GenericItemViewModel"/> class using the specified item data. /// </summary> /// <param name="data">The item data used to configure the view model.</param> public GenericItemViewModel(ItemData data) { if (data == null) { throw new ArgumentNullException("data"); } SetContent(data.OfflineContent); }
private static ItemData LoadItemData(XElement itemElement) { var result = new ItemData(); // get data result.Title = GetAttributeValue(itemElement, AttributeTitle); var typeText = GetAttributeValue(itemElement, AttributeType); result.ItemType = (ItemType)Enum.Parse(typeof(ItemType), typeText, true); var url = GetAttributeValue(itemElement, AttributeUri); if (!string.IsNullOrEmpty(url)) { result.Uri = new Uri(url, UriKind.RelativeOrAbsolute); } // get the (alternate) content var child = itemElement.Descendants().FirstOrDefault(); if (child != null) { // we have XML content here // => use ToString() here to preserve the content as XML (it's likely XAML) result.OfflineContent = child.ToString(); } else { // no child elements => use the content as text result.OfflineContent = itemElement.Value; } return result; }