private void SetTreeViewItemVisibility() { if (ShowLayersVisibleAtScale) { bool isNodeVisible = IsInScaleRange == true; if (isNodeVisible) { LayerItemViewModel mod = this.DataContext as LayerItemViewModel; if (mod != null && mod.LayerItems != null) { LayerItemViewModel child = mod.LayerItems.FirstOrDefault(lm => lm.IsInScaleRange); if (child == null) { isNodeVisible = false; } } } //hide the node if not visible at current extent TreeViewItem item = ControlTreeHelper.FindAncestorOfType <TreeViewItem>(this); if (item != null) { item.Visibility = isNodeVisible ? Visibility.Visible : Visibility.Collapsed; if (item.Visibility == Visibility.Visible) { EnsureAncestorsVisible(item); } } } }
private void EnsureAncestorsVisible(TreeViewItem item) { TreeViewItem parent = ControlTreeHelper.FindAncestorOfType <TreeViewItem>(item); if (parent != null) { if (parent.Visibility != Visibility.Visible) { parent.Visibility = Visibility.Visible; } EnsureAncestorsVisible(parent); } }
internal void EnableRenameForLayer(Layer layer) { if (!Configuration.AllowLayerSelection) { return; } if (layer == null) { return; } if (_legend != null) { try { List <TreeViewItemExtended> treeViewItems = ControlTreeHelper.FindChildrenOfType <TreeViewItemExtended>(_legend, 1); if (treeViewItems != null) { foreach (TreeViewItemExtended item in treeViewItems) { LayerItemViewModel model = item.DataContext as LayerItemViewModel; if (model != null && layer == model.Layer) { StackPanel panel = ControlTreeHelper.FindChildOfType <StackPanel>(item, 6); if (panel != null && panel.Name == "layerStackPanel") { panel.SetValue(CoreExtensions.IsEditProperty, true); } return; } } } } catch { } } }
void AssociatedObject_Checked(object sender, RoutedEventArgs e) { LayerInfo layerInfo = AssociatedObject.DataContext as LayerInfo; if (layerInfo != null && layerInfo.Layer != null && !string.IsNullOrWhiteSpace(layerInfo.Layer.ID)) { MapContentsConfigControl parentConfigControl = ControlTreeHelper.FindAncestorOfType <MapContentsConfigControl>(AssociatedObject); if (parentConfigControl != null) { MapContentsConfiguration conf = parentConfigControl.DataContext as MapContentsConfiguration; if (conf != null) { List <string> excludedLayers = conf.ExcludedLayerIds == null ? null : conf.ExcludedLayerIds.ToList <string>(); if (AssociatedObject.IsChecked == true) { if (excludedLayers == null) { conf.ExcludedLayerIds = new string[] { layerInfo.Layer.ID }; } else if (!excludedLayers.Contains(layerInfo.Layer.ID)) { excludedLayers.Add(layerInfo.Layer.ID); conf.ExcludedLayerIds = excludedLayers.ToArray(); } } else { if (excludedLayers != null) { excludedLayers.Remove(layerInfo.Layer.ID); conf.ExcludedLayerIds = excludedLayers.ToArray(); } } } } } }
void AssociatedObject_MouseRightButtonUp(object sender, MouseButtonEventArgs e) { MapContents cont = ControlTreeHelper.FindAncestorOfType <MapContents>(AssociatedObject); if (cont == null) { return; } MapContentsConfiguration conf = cont.DataContext as MapContentsConfiguration; if (conf == null) { return; } if (ToolPanels.Current != null && !string.IsNullOrWhiteSpace(conf.ContextMenuToolPanelName)) { _toolPanel = ToolPanels.Current[conf.ContextMenuToolPanelName]; } if (_toolPanel == null) { return; } _contextMenu = new ContextMenu(); if (ContextMenuStyle != null) { _contextMenu.Style = ContextMenuStyle; } // Bind background and foreground properties to context menu Binding b = new Binding("ContextMenuBackground") { Source = this }; _contextMenu.SetBinding(ContextMenu.BackgroundProperty, b); b = new Binding("ContextMenuForeground") { Source = this }; _contextMenu.SetBinding(ContextMenu.ForegroundProperty, b); // set the control to the current culture settings (LTR/RTL) RTLHelper helper = System.Windows.Application.Current.Resources["RTLHelper"] as RTLHelper; Debug.Assert(helper != null); if (helper != null) { _contextMenu.FlowDirection = helper.FlowDirection; } foreach (FrameworkElement button in _toolPanel.ToolPanelItems) { System.Windows.Controls.Primitives.ButtonBase btnBase = button as System.Windows.Controls.Primitives.ButtonBase; if (btnBase != null) { MenuItem item = new MenuItem(); ButtonDisplayInfo info = btnBase.DataContext as ButtonDisplayInfo; if (info != null) { item.Header = info.Label; if (!string.IsNullOrEmpty(info.Icon)) { Image image = new Image(); Binding binding = new Binding("Icon") { Converter = _urlResolver }; image.SetBinding(Image.SourceProperty, binding); image.DataContext = info; item.Icon = image; } item.Command = btnBase.Command; _contextMenu.Items.Add(item); } } else { _contextMenu.Items.Add(new Separator()); } } Point point = e.GetPosition(null); if (point != null) { _contextMenu.HorizontalOffset = point.X; _contextMenu.VerticalOffset = point.Y; } LayerItemViewModel layerViewModel = AssociatedObject.DataContext as LayerItemViewModel; if (layerViewModel != null && layerViewModel.Layer != null) { if (!CoreExtensions.GetIsSelected(layerViewModel.Layer)) { SetSelectedLayer(layerViewModel.Layer); } } if (_contextMenu.Items.Count > 0) { _contextMenu.IsOpen = true; if (_contextMenu.FlowDirection == FlowDirection.RightToLeft) { // Now that the popup is open, we can update the layout measurements so that // the ActualWidth is available. _contextMenu.UpdateLayout(); _contextMenu.HorizontalOffset -= _contextMenu.ActualWidth; } } }