private IEnumerable<Rank> ParseRanks(IEnumerable<XElement> nodes) { var ranks = new List<Rank>(); foreach (var node in nodes) { int difficulty = int.Parse(node.Attribute("difficulty").Value); var huntNodes = node.Elements("Hunt"); var rank = new Rank(huntNodes); rank.Difficulty = difficulty; rank.Reward = node.Attribute("reward").Value; ranks.Add(rank); } return ranks; }
/// <summary> /// Populates the page with content passed during navigation. Any saved state is also /// provided when recreating a page from a prior session. /// </summary> /// <param name="navigationParameter">The parameter value passed to /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested. /// </param> /// <param name="pageState">A dictionary of state preserved by this page during an earlier /// session. This will be null the first time a page is visited.</param> protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState) { _rank = navigationParameter as Rank; var huntItems = _rank.Hunts.OrderBy(x => x.Level) .Select(x => new HuntViewModel { Title = x.Title, Subtitle = x.Reward, Description = x.Tasks.Count() == 1 ? "1 monster" : x.Tasks.Count() + " monsters", Image = string.Empty, Monsters = x.Tasks.Select(task => new MonsterViewModel { Image = string.Empty, Name = task.Monster, Quantity = task.Quantity, Task = task }) }); // TODO: Assign a bindable group to this.DefaultViewModel["Group"] this.DefaultViewModel["Group"] = new {Title = "Hunts"}; // TODO: Assign a collection of bindable items to this.DefaultViewModel["Items"] this.DefaultViewModel["Items"] = huntItems; if (pageState == null) { // When this is a new page, select the first item automatically unless logical page // navigation is being used (see the logical page navigation #region below.) if (!this.UsingLogicalPageNavigation() && this.itemsViewSource.View != null) { this.itemsViewSource.View.MoveCurrentToFirst(); } } else { // Restore the previously saved state associated with this page if (pageState.ContainsKey("SelectedItem") && this.itemsViewSource.View != null) { // TODO: Invoke this.itemsViewSource.View.MoveCurrentTo() with the selected // item as specified by the value of pageState["SelectedItem"] HuntViewModel targetItem = pageState["SelectedItem"] as HuntViewModel; int index = huntItems.TakeWhile(hunt => hunt.Title != targetItem.Title).Count(); this.itemsViewSource.View.MoveCurrentToPosition(index); } } }