Beispiel #1
0
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            if (item is DrillDownMenuItem)
            {
                DrillDownMenuItem menuItem = item as DrillDownMenuItem;

                if (menuItem.IsFolder)
                {
                    return(FolderTemplate);
                }
                else
                {
                    if (menuItem.IsBackItem)
                    {
                        return(BackButtonTemplate);
                    }
                    else
                    {
                        return(MenuItemTemplate);
                    }
                }
            }
            else
            {
                return(MenuItemTemplate); // base.SelectTemplate(item, container);
            }
        }
        public virtual object Clone()
        {
            DrillDownMenuItem clone = new DrillDownMenuItem
            {
                SearchText = this.SearchText,
                Caption    = this.Caption,
                Id         = this.Id,
                IsBackItem = this.IsBackItem,
                IsEnabled  = this.IsEnabled,
                IsFolder   = this.IsFolder,
                IsReadOnly = this.IsReadOnly
            };

            ObservableCollection <DrillDownMenuItem> children = new ObservableCollection <DrillDownMenuItem>();

            foreach (DrillDownMenuItem child in this.Children)
            {
                DrillDownMenuItem childClone = child.Clone() as DrillDownMenuItem;
                childClone.Parent = clone;
                children.Add(childClone);
            }

            clone.Children = children;

            return(clone);
        }
 private void MenuItemSelectedEventHandler(DrillDownMenuItem selectedMenuItem)
 {
     if (selectedMenuItem.IsFolder)
     {
         this.Header   = selectedMenuItem.Caption;
         CurrentFolder = selectedMenuItem;
     }
 }
        private void SearchRecursive(DrillDownMenuItem item, string searchText, IList <DrillDownMenuItem> resultItems, bool recursion = false)
        {
            if (!recursion)
            {
                searchText = searchText.ToLower();
                searchText = searchText.Trim();

                resultListExactMatchIndex     = 0;
                resultListStartWithMatchIndex = 0;
                resultListInMatchIndex        = 0;
            }

            if (item != null)
            {
                if (!item.IsFolder && !item.IsBackItem)
                {
                    string itemText    = item.SearchText.ToLower();
                    int    insertIndex = -1;

                    if (itemText == searchText)
                    {
                        insertIndex = resultListExactMatchIndex;
                        resultListExactMatchIndex++;
                        resultListStartWithMatchIndex++;
                        resultListInMatchIndex++;
                    }
                    else if (itemText.StartsWith(searchText))
                    {
                        insertIndex = resultListStartWithMatchIndex;
                        resultListStartWithMatchIndex++;
                        resultListInMatchIndex++;
                    }
                    else if (itemText.Contains(searchText))
                    {
                        insertIndex = resultListInMatchIndex;
                        resultListInMatchIndex++;
                    }

                    if (insertIndex > -1)
                    {
                        if (resultItems.Count(listItem => listItem.Id == item.Id) == 0)
                        {
                            resultItems.Insert(insertIndex, item);
                        }
                    }
                }

                foreach (DrillDownMenuItem child in item.Children)
                {
                    SearchRecursive(child, searchText, resultItems, true);
                }
            }
        }
        private void AdjustCaptionBinding()
        {
            if ((isBackItem) && (parent != null))
            {
                DrillDownMenuItem backParent = parent.Parent != null ? parent.Parent : parent;

                BindingOperations.SetBinding(this, DrillDownMenuItem.CaptionProperty, new Binding()
                {
                    Source = backParent,
                    Path   = new PropertyPath("Caption")
                });
            }
        }
        private void TryNavigateDown(object selectedItem)
        {
            MenuItemSelectedEventArgs args;
            bool raiseEvent = true;

            // If we have wrappped the entries
            DrillDownMenuItem selectedMenuItem = selectedItem as DrillDownMenuItem;

            if (selectedMenuItem != null)
            {
                if (selectedMenuItem.IsEnabled)
                {
                    if (selectedMenuItem.IsFolder)
                    {
                        _searchManager.Reset();
                        this.Header = selectedMenuItem.Caption;
                        (_presenter.Transition as SlideTransition).Mode = TransitionMode.In;
                        CurrentFolder = selectedMenuItem;
                    }
                }

                if (selectedMenuItem.IsBackItem)
                {
                    NavigateBack();
                    raiseEvent = false;
                }
            }

            if (raiseEvent)
            {
                // Raise external event
                args = new MenuItemSelectedEventArgs(MenuItemSelectedEvent, selectedItem);
                RaiseEvent(args);
                _currentListBox.SelectedItem = null;

                if ((_currentListBox.Items.Count > 0) && (selectedItem != _currentListBox.Items[0]))
                {
                    _currentListBox.SelectedItem = _currentListBox.Items[0];
                }
            }

            /*
             * if (registerKeyTips)
             * {
             *  RegisterKeyTips(this);
             * }
             */
        }
        private void FolderSearchRecursion(DrillDownMenuItem currentMenuItem, List <DrillDownMenuItem> folderList)
        {
            if (currentMenuItem.IsFolder && !currentMenuItem.IsBackItem)
            {
                folderList.Add(currentMenuItem);

                List <DrillDownMenuItem> childFolders = currentMenuItem.Children.Where(m => m.IsFolder && !m.IsBackItem).ToList();

                if (childFolders.Count > 0)
                {
                    foreach (DrillDownMenuItem childFolder in childFolders)
                    {
                        FolderSearchRecursion(childFolder, folderList);
                    }
                }
            }
        }
        private void NavigateBack()
        {
            if ((CurrentFolder != null) && (CurrentFolder.Parent == null))
            {
                return;
            }

            DrillDownMenuItem selectedMenuItem = CurrentFolder.Parent;

            (_presenter.Transition as SlideTransition).Mode = TransitionMode.Out;

            CurrentFolder = selectedMenuItem;

            if ((_currentListBox.Items.Count > 0) && (_currentListBox.SelectedItem != _currentListBox.Items[0]))
            {
                _currentListBox.SelectedItem = _currentListBox.Items[0];
            }
        }
        void SearchServiceQueryCompleted(object result, Exception e)
        {
            if (result != null)
            {
                DrillDownMenuItem root = new DrillDownMenuItem();
                root.Caption  = SearchResultText;
                root.IsFolder = true;

                DrillDownMenuItem temp = root;

                IList <DrillDownMenuItem> resultItems = result as IList <DrillDownMenuItem>;

                for (int i = 0; i < resultItems.Count; i++)
                {
                    if ((i % 20 == 0) && (i > 0))
                    {
                        DrillDownMenuItem sub = new DrillDownMenuItem();
                        sub.IsFolder = true;
                        sub.Caption  = MoreResultsText;
                        sub.Parent   = temp;
                        temp.Children.Add(sub);
                        temp = sub;
                    }

                    temp.Children.Add(resultItems[i]);
                }

                this.CurrentFolder = root;

                if (_currentListBox.Items.Count > 0)
                {
                    _currentListBox.SelectedItem = _currentListBox.Items[0];
                }
            }

            ongoingSearches--;

            if (ongoingSearches <= 0)
            {
                searchFinishedEvent.Set();
            }
        }
        public DrillDownMenuItem GetDropTarget(DragEventArgs e)
        {
            DrillDownMenuItem dropTarget = null;

            for (int i = 0; i < _currentListBox.Items.Count; i++)
            {
                ListBoxItem lbi = _currentListBox.ItemContainerGenerator.ContainerFromIndex(i) as ListBoxItem;
                if (lbi == null)
                {
                    continue;
                }
                if (IsMouseOverTarget(lbi, e.GetPosition((IInputElement)lbi)))
                {
                    dropTarget = (DrillDownMenuItem)_currentListBox.Items[i];
                    break;
                }
            }

            return(dropTarget);
        }