private void ListBoxItemContextMenuClosing(object sender, ContextMenuEventArgs e)
 {
     if (tmpRelayCommand != null)
     {
         DataRepositoryHelper.RestoreFirstMenuItemCommand(sender, tmpRelayCommand);
     }
 }
        private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            DataRepositoryItem[] selectedItems = ChildrenList.SelectedItems.OfType <DataRepositoryItem>().ToArray();
            if (selectedItems.Length > 1)
            {
                DataRepositoryContentViewModel.Current.PlaceOnMapCommand = DataRepositoryHelper.GetPlaceMultipleFilesCommand(selectedItems);

                DataRepositoryItem dataRepositoryItem = selectedItems[0];
                DataRepositoryContentViewModel.Current.ContextMenuStackPanel = DataRepositoryContentUserControl.ConvertContextMenuToButton(dataRepositoryItem.ContextMenu, DataRepositoryContentViewModel.Current.PlaceOnMapCommand);
            }
            else if (selectedItems.Length == 1)
            {
                DataRepositoryItem dataRepositoryItem = selectedItems[0];
                if (dataRepositoryItem != null && dataRepositoryItem.ContextMenu != null)
                {
                    DataRepositoryContentViewModel.Current.ContextMenuStackPanel = DataRepositoryContentUserControl.ConvertContextMenuToButton(dataRepositoryItem.ContextMenu);
                }

                if (dataRepositoryItem != null && dataRepositoryItem.IsLoadable)
                {
                    DataRepositoryContentViewModel.Current.PlaceOnMapCommand = ((MenuItem)selectedItems.First().ContextMenu.Items[0]).Command;
                }
                else
                {
                    DataRepositoryContentViewModel.Current.PlaceOnMapCommand = null;
                }
            }
        }
        private void ListBoxItemContextMenuOpening(object sender, ContextMenuEventArgs e)
        {
            var selectedItems = ChildrenList.SelectedItems.OfType <DataRepositoryItem>().ToArray();

            if (selectedItems.Length > 1)
            {
                DataRepositoryHelper.AddSelectedItemsToMap(selectedItems, sender, ref tmpRelayCommand);
            }

            DataRepositoryItem dataRepositoryItem = sender.GetDataContext <DataRepositoryItem>();

            if (dataRepositoryItem != null && !dataRepositoryItem.CanRename)
            {
                var listItem = sender as ListBoxItem;
                if (listItem != null)
                {
                    // listItem.DataContext
                    foreach (MenuItem menu in listItem.ContextMenu.Items)
                    {
                        if (menu.Header.Equals("Rename"))
                        {
                            menu.Visibility = Visibility.Collapsed;
                        }
                    }
                }
            }
        }