/// <summary> /// Handles the <see cref="Selector.SelectionChanged"/> event for the "Entity Class" <see /// cref="ListView"/>.</summary> /// <param name="sender"> /// The <see cref="Object"/> where the event handler is attached.</param> /// <param name="args"> /// A <see cref="SelectionChangedEventArgs"/> object containing event data.</param> /// <remarks> /// <b>OnClassSelected</b> updates the "Site" list view to reflect the selected item in the /// "Entity Class" list view, and then selects the first item in that list view, if any. /// </remarks> private void OnClassSelected(object sender, SelectionChangedEventArgs args) { args.Handled = true; // clear Site list view & map view SiteList.ItemsSource = null; Array.Clear(this._mapView.SelectedRegion, 0, this._mapView.SelectedRegion.Length); this._mapView.Redraw(); // retrieve selected entity class, if any int index = ClassList.SelectedIndex; if (index < 0) { return; } ClassListItem item = (ClassListItem)ClassList.Items[index]; EntityClass entityClass = item.Item1; // retrieve placement sites, if any var targets = this._classTargets[entityClass.Id]; List <SiteListItem> items = new List <SiteListItem>(targets.Count); // add sites to list view & selected region foreach (PointI target in targets) { this._mapView.SelectedRegion[target.X, target.Y] = true; // get site at specified coordinates Site site = this._worldState.GetSite(target); // get owner of this site, if any string owner = (site.Owner == null ? ShowPlacements.OwnerNone : site.Owner.ToString()); items.Add(new SiteListItem(site.ToString(), owner, target)); } // redraw highlighted region this._mapView.Redraw(); // use ItemsSource for sorting & virtualization items.Sort((x, y) => String.CompareOrdinal(x.Item1, y.Item1)); SiteList.ItemsSource = items; // select first site, if any if (SiteList.Items.Count > 0) { SiteList.SelectedIndex = 0; } }
/// <summary> /// Handles the <see cref="Control.MouseDoubleClick"/> event for a <see /// cref="ListViewItem"/> of the "Entity Class" <see cref="ListView"/>.</summary> /// <param name="sender"> /// The <see cref="Object"/> where the event handler is attached.</param> /// <param name="args"> /// A <see cref="MouseButtonEventArgs"/> object containing event data.</param> /// <remarks> /// <b>OnClassActivate</b> displays a <see cref="ShowClasses"/> dialog containing /// information on the double-clicked item in the "Entity Class" list view.</remarks> private void OnClassActivate(object sender, MouseButtonEventArgs args) { args.Handled = true; // retrieve double-clicked item, if any var source = args.OriginalSource as DependencyObject; var listItem = ItemsControl.ContainerFromElement(ClassList, source) as ListViewItem; if (listItem == null) { return; } // show info dialog for entity class ClassListItem item = (ClassListItem)listItem.Content; var dialog = new ShowClasses(item.Item1) { Owner = this }; dialog.ShowDialog(); }