private void removeMapBehavior(ExtensionBehavior extensionBehavior) { if (MapApplication.Current == null && MapApplication.Current.Map != null) return; BehaviorCollection behaviors = Interaction.GetBehaviors(MapApplication.Current.Map); if (behaviors == null) return; Behavior<Map> mapBehavior = extensionBehavior.MapBehavior as Behavior<Map>; if (mapBehavior == null) { mapBehavior = BehaviorUtils.GetMapBehavior(extensionBehavior); extensionBehavior.MapBehavior = mapBehavior; } if (mapBehavior == null) return; behaviors.Remove(mapBehavior); if (View.Instance != null && View.Instance.ExtensionBehaviors != null && View.Instance.ExtensionBehaviors.Contains(extensionBehavior)) { View.Instance.ExtensionBehaviors.Remove(extensionBehavior); } }
public static Behavior<Map> GetMapBehavior(ExtensionBehavior extensionBehavior) { if (extensionBehavior == null || string.IsNullOrEmpty(extensionBehavior.CommandValueId)) return null; if (extensionBehavior.MapBehavior != null) return extensionBehavior.MapBehavior as Behavior<Map>; string[] splits = extensionBehavior.CommandValueId.Split(new char[] { ';' }); if (splits == null || splits.Length < 2) return null; string typeName = splits[0].Replace("Type=", ""); string assemblyName = splits[1].Replace("Assembly=", ""); foreach (Behavior<Map> mapBehavior in View.Instance.ExtensionMapBehaviors) { if (mapBehavior == null) continue; Type type = mapBehavior.GetType(); if (type.FullName == typeName && type.Assembly.FullName == assemblyName) { return type.Assembly.CreateInstance(type.FullName) as Behavior<Map>; } } return null; }
private void addRemoveMapBehavior(ExtensionBehavior extensionBehavior) { if (MapApplication.Current == null && MapApplication.Current.Map != null) return; BehaviorCollection behaviors = Interaction.GetBehaviors(MapApplication.Current.Map); if (behaviors == null) return; Behavior<Map> mapBehavior = extensionBehavior.MapBehavior as Behavior<Map>; if (mapBehavior == null) { mapBehavior = BehaviorUtils.GetMapBehavior(extensionBehavior); extensionBehavior.MapBehavior = mapBehavior; } if (mapBehavior == null) return; if (extensionBehavior.IsEnabled) { if (!behaviors.Contains(mapBehavior)) behaviors.Add(mapBehavior); } else behaviors.Remove(mapBehavior); }
void ExtensionBehaviors_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { if (e.NewItems != null && e.NewItems.Count > 0) selectedExtension = e.NewItems[0] as ExtensionBehavior; if (ExtensionBehaviors.Count == 0) selectedExtension = null; if (MapBehaviorsDataGrid != null && selectedExtension != null) MapBehaviorsDataGrid.SelectedItem = selectedExtension; }
public override void OnApplyTemplate() { base.OnApplyTemplate(); if (ExtensionBehaviors != null) { if (selectedExtension == null && ExtensionBehaviors.Count > 0) selectedExtension = ExtensionBehaviors[0]; ExtensionBehaviors.CollectionChanged -= ExtensionBehaviors_CollectionChanged; ExtensionBehaviors.CollectionChanged += ExtensionBehaviors_CollectionChanged; } MapBehaviorsDataGrid = GetTemplateChild("MapBehaviorsDataGrid") as System.Windows.Controls.DataGrid; if (MapBehaviorsDataGrid != null) { MapBehaviorsDataGrid.SelectedItem = selectedExtension; MapBehaviorsDataGrid.LoadingRow -= MapBehaviorsDataGrid_LoadingRow; MapBehaviorsDataGrid.LoadingRow += MapBehaviorsDataGrid_LoadingRow; } }
public Behavior<Client.Map> getMapBehaviorForExtensionBehavior(ExtensionBehavior extensionBehavior) { if (ExtensionMapBehaviors == null || extensionBehavior == null || string.IsNullOrEmpty(extensionBehavior.CommandValueId)) return null; if (extensionBehavior.MapBehavior != null) return extensionBehavior.MapBehavior; string[] splits = extensionBehavior.CommandValueId.Split(new char[] { ';' }); if (splits == null || splits.Length < 2) return null; string typeName = splits[0].Replace("Type=", ""); string assemblyName = splits[1].Replace("Assembly=", ""); if (!assemblyName.Contains("Version=")) assemblyName = this.GetType().Assembly.FullName.Replace("ESRI.ArcGIS.Mapping.Controls", assemblyName); foreach (Behavior<Map> mapBehavior in ExtensionMapBehaviors) { if (mapBehavior == null) continue; Type type = mapBehavior.GetType(); if (type.FullName == typeName && type.Assembly.FullName == assemblyName) { return type.Assembly.CreateInstance(type.FullName) as Behavior<Map>; } } Type t = Type.GetType(string.Format("{0},{1}", typeName, assemblyName)); if(t != null) return t.Assembly.CreateInstance(t.FullName) as Behavior<Map>; return null; }
private void AddItemTree_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e) { ExtensionBehavior behavior = null; TreeViewItem selectedAddItem = AddItemTree.SelectedItem as TreeViewItem; // There has to be a selected add item and its parent cannot be the tree itself (which implies it is a child of // a category parent node) in which case the OK button can be enabled. if (selectedAddItem != null && selectedAddItem.Parent != AddItemTree) { ExtensionBehavior itemToAdd = selectedAddItem.Tag as ExtensionBehavior; if (itemToAdd != null) { // Use the button base, but clone the button info object so that if the user edits the associated // values in this copy, it will not alter the original values in the "Add Tools" treeview. behavior = new ExtensionBehavior(); behavior.BehaviorId = Guid.NewGuid().ToString(); behavior.MapBehavior = Activator.CreateInstance(itemToAdd.MapBehavior.GetType()) as Behavior<Map>; behavior.IsEnabled = true; behavior.Title = itemToAdd.Title; } } SelectedItem = behavior; if (SelectedItemChanged != null) SelectedItemChanged(this, EventArgs.Empty); }
private TreeViewItem createTreeViewNodeForToolButton(ExtensionBehavior behavior) { TreeViewItem node = new TreeViewItem() { Header = behavior.Title, Tag = behavior, Style = AddItemTree.ItemContainerStyle }; return node; }
private void buildAddItemTree() { // Clear all items in the tree control then add those determined in the constructor AddItemTree.Items.Clear(); if (addItems == null) return; // Process all elements of the item list, dynamically creating parent category nodes and attaching // child nodes to these parents. string curCategory = null; TreeViewItem parent = null; bool isSelected = false; foreach (AddBehaviorItem item in addItems) { // If the current category does not match the category of the current item then create a new category node if (String.Compare(curCategory, item.Category) != 0) { // Make this parent node selected only if the current category value is null so that the top category is selected // but none of the subsequent category nodes are selected. isSelected = curCategory == null ? true : false; TreeViewItem tvi = new TreeViewItem() { Name = item.Category, Header = item.Category, IsExpanded = true, IsSelected = isSelected, }; AddItemTree.Items.Add(tvi); // Assign the item category as the "current" category and assign the newly created category node as the // parent to which all subsequent items are added. curCategory = item.Category; parent = tvi; } // Create an instance of the type Behavior<Map> behavior = Activator.CreateInstance(item.BehaviorType) as Behavior<Map>; // Create a button display info object in order to store all the associated data which is // bound to the tree control for proper rendering. ExtensionBehavior bdi = new ExtensionBehavior(); bdi.BehaviorId = Guid.NewGuid().ToString(); bdi.Title = item.Name; bdi.IsEnabled = true; bdi.MapBehavior = behavior; // Convert the button into a tree view item and associate proper styles, etc. TreeViewItem child = createTreeViewNodeForToolButton(bdi); child.Name = item.Category + item.Name + item.BehaviorType.ToString(); // Use item description (if any) for the tooltip if (!String.IsNullOrEmpty(item.Description)) child.SetValue(ToolTipService.ToolTipProperty, item.Description); // Add child to parent node parent.Items.Add(child); } }