/// <summary> /// Handles the <see cref="ButtonBase.Click"/> event for the "Change Terrain" <see /// cref="Button"/> on the <see cref="TerrainTab"/> page.</summary> /// <param name="sender"> /// The <see cref="Object"/> where the event handler is attached.</param> /// <param name="args"> /// A <see cref="RoutedEventArgs"/> object containing event data.</param> /// <remarks> /// <b>OnBackgroundChange</b> shows the <see cref="Dialog.ChangeTemplate"/> dialog with the /// selected item in the "Terrain Class" combo box, if any, and calls <see /// cref="OnTerrainTabChanged"/> if the user made any changes.</remarks> private void OnBackgroundChange(object sender, RoutedEventArgs args) { args.Handled = true; if (!this._initialized) { return; } // retrieve background terrain, if any EntityTemplate template = (EntityTemplate)BackgroundCombo.Tag; if (template == null) { return; } // attempt to find underlying entity class EntityClass entityClass; if (!ChangeTemplate.CanEdit(this, template, out entityClass)) { return; } // show Change Template dialog var dialog = new ChangeTemplate(template, entityClass) { Owner = this }; dialog.ShowDialog(); // broadcast data changes if (dialog.DataChanged) { OnTerrainTabChanged(); } }
/// <summary> /// Handles the <see cref="ButtonBase.Click"/> event for the "Change Entity" <see /// cref="Button"/> and the <see cref="Control.MouseDoubleClick"/> event for the "Entity /// Stack" <see cref="ListView"/> on any tab page.</summary> /// <param name="sender"> /// The <see cref="Object"/> where the event handler is attached.</param> /// <param name="args"> /// A <see cref="RoutedEventArgs"/> object containing event data.</param> /// <remarks> /// <b>OnEntityChange</b> shows the <see cref="Dialog.ChangeTemplate"/> dialog with either /// the first selected item or the double-clicked item in the "Entity Stack" list view, /// depending on the exact type of the specified <paramref name="args"/>, and sets the <see /// cref="DataChanged"/> flag if the user made any changes.</remarks> private void OnEntityChange(object sender, RoutedEventArgs args) { args.Handled = true; ListView stackList; Action onDataChanged; if (TerrainTab.IsSelected) { stackList = TerrainList; onDataChanged = OnTerrainTabChanged; } else { stackList = EntityList; onDataChanged = OnOtherTabChanged; } // determine which event occurred int index = -1; if (args.RoutedEvent == ListViewItem.MouseDoubleClickEvent) { // retrieve double-clicked entity, if any var source = args.OriginalSource as DependencyObject; var listItem = ItemsControl.ContainerFromElement(stackList, source) as ListViewItem; if (listItem != null) { index = stackList.Items.IndexOf(listItem.Content); } } else { // retrieve selected entity, if any index = stackList.SelectedIndex; } if (index < 0) { return; } EntityListItem item = (EntityListItem)stackList.Items[index]; EntityTemplate template = item.Item2; // attempt to find underlying entity class EntityClass entityClass; if (!ChangeTemplate.CanEdit(this, template, out entityClass)) { return; } // show Change Template dialog var dialog = new ChangeTemplate(template, entityClass) { Owner = this }; dialog.ShowDialog(); // broadcast data changes if (dialog.DataChanged) { item = new EntityListItem(GetEntityText(template), item.Item2); stackList.Items[index] = item; stackList.SelectAndShow(index); onDataChanged(); } }