Beispiel #1
0
        public void SetImage(int imgIndex)
        {
            if (imgIndex > main.ImageFiles.Count)
            {
                imgIndex = main.ImageFiles.Count;
            }
            if (currentImageOffset > imgIndex)
            {
                currentImageOffset = (int)Math.Floor((float)imgIndex / maxLoadedSquares) * maxLoadedSquares;
                currentChunk       = 0;
                foreach (var image in Images)
                {
                    image.Unload();
                }
                Images.Clear();
                GC.Collect();
            }
            var index     = imgIndex - currentImageOffset;
            var numChunks = (int)Math.Ceiling((float)index / imagesPerChunk);

            for (int i = currentChunk; i < numChunks; i++)
            {
                LoadNextChunk();
            }
            ImageGrid.SelectedIndex = index;
            ListBoxItem myListBoxItem = (ListBoxItem)(ImageGrid.ItemContainerGenerator.ContainerFromItem(ImageGrid.Items[index]));

            if (myListBoxItem != null)
            {
                myListBoxItem.Focus();
                Keyboard.Focus(myListBoxItem);
                myListBoxItem.BringIntoView();
                //main.imageGrid_ScrollViewer.sc.ScrollIntoView(myListBoxItem);
            }
        }
Beispiel #2
0
        public static void SelectListBoxItem(ListBox lb, object itemToSelect)
        {
            ListBoxItem lbi = (ListBoxItem)lb.ItemContainerGenerator.ContainerFromItem(itemToSelect);

            if (lbi != null)
            {
                lbi.IsSelected = true;
                lbi.BringIntoView();

                TextBox tb = UIHelpers.FindVisualChild <TextBox>(lbi);
                if (tb != null && !tb.IsFocused)
                {
                    tb.Focus();
                }
            }
            else
            {
                EventHandler eh = null;
                eh = new EventHandler(delegate
                {
                    if (lb.ItemContainerGenerator.Status == System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated)
                    {
                        SelectListBoxItem(lb, itemToSelect);

                        //remove the StatusChanged event handler since we just handled it (we only needed it once)
                        lb.ItemContainerGenerator.StatusChanged -= eh;
                    }
                });
                lb.ItemContainerGenerator.StatusChanged += eh;
            }
        }
Beispiel #3
0
        private void ListBoxItem_OnSelected(object sender, RoutedEventArgs e)
        {
            ListBoxItem item = e.OriginalSource as ListBoxItem;

            if (item != null)
            {
                item.BringIntoView();
            }
        }
Beispiel #4
0
 private void PropertyReporter_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
 {
     if (e.PropertyName == "IsError")
     {
         OnPropertyChanged("StatusColor");
     }
     else if (e.PropertyName == "Started")
     {
         OnPropertyChanged("RunButtonString");
     }
     else if (e.PropertyName == "CurrentJob")
     {
         // scroll to that job in the task list
         Action callback = new Action(() =>
         {
             Job job = ((ProgressReporter)sender).CurrentJob;
             if (job != null && _currentJob != job)
             {
                 ListBoxItem item = (ListBoxItem)JobListBox.ItemContainerGenerator.ContainerFromItem(job);
                 if (item == null)
                 {
                     JobListBox.UpdateLayout();
                     item = (ListBoxItem)JobListBox.ItemContainerGenerator.ContainerFromItem(job);
                 }
                 if (item != null && item.Content == job)
                 {
                     item.BringIntoView();
                 }
             }
             _currentJob = job;
         });
         if (Dispatcher.CheckAccess())
         {
             callback.Invoke();
         }
         else
         {
             Dispatcher.InvokeAsync(callback);
         }
     }
     else if (e.PropertyName == "Shutdown")
     {
         OnPropertyChanged("RunButtonString");
     }
     else if (e.PropertyName == "LogDocument")
     {
         if (_logRichTextBoxScroll != null)
         {
             if (_isLogScrollAtEnd)
             {
                 _logRichTextBoxScroll.ScrollToEnd();
             }
         }
     }
 }
        private void ListBoxItem_Selected(object sender, RoutedEventArgs e)
        {
            ListBoxItem        item   = sender as ListBoxItem;
            SlideButtonControl button = item.Content as SlideButtonControl;

            CurrentSlide = button.slide;

            item.BringIntoView();

            DisplaySlide(CurrentSlide);
        }
    static void OnListBoxItemSelected(object sender, RoutedEventArgs e)
    {
        // Only react to the Selected event raised by the ListBoxItem
        // whose IsSelected property was modified.  Ignore all ancestors
        // who are merely reporting that a descendant's Selected fired.
        if (!Object.ReferenceEquals(sender, e.OriginalSource))
        {
            return;
        }
        ListBoxItem item = e.OriginalSource as ListBoxItem;

        if (item != null)
        {
            item.BringIntoView();
        }
    }
Beispiel #7
0
        public void ScrollIntoView(object o, SelectionChangedEventArgs e)
        {
            ListBox b = (ListBox)o;

            if (b.SelectedItem == null)
            {
                return;
            }

            ListBoxItem item = (ListBoxItem)((ListBox)o).ItemContainerGenerator.ContainerFromItem(((ListBox)o).SelectedItem);

            if (item != null)
            {
                item.BringIntoView();
            }
        }
Beispiel #8
0
        /// <summary>
        /// First determine whether the drag data is supported.
        /// Finally handle the actual drop when <code>bDrop</code> is true.
        /// Insert the item before the drop target.  When there is no drop
        /// target (dropped on empty space), add to the end of the items.
        ///
        /// Note that only TreeViewItems with no children can be moved.
        /// </summary>
        /// <param name="bDrop">True to perform an actual drop, otherwise just return e.Effects</param>
        /// <param name="sender">DragDrop event <code>sender</code></param>
        /// <param name="e">DragDrop event arguments</param>
        private void DragOverOrDrop(bool bDrop, object sender, DragEventArgs e)
        {
            TreeViewDataProvider <TSourceContainer, TSourceObject> dataProvider = this.GetData(e) as TreeViewDataProvider <TSourceContainer, TSourceObject>;

            if (dataProvider != null)
            {
                TSourceObject    dragSourceObject    = dataProvider.SourceObject as TSourceObject;
                TSourceContainer dragSourceContainer = dataProvider.SourceContainer as TSourceContainer;
                Debug.Assert(dragSourceObject != null);
                Debug.Assert(dragSourceContainer != null);

                ListBox     dropContainer = Utilities.FindParentControlIncludingMe <ListBox>(e.Source as DependencyObject);
                ListBoxItem dropTarget    = Utilities.FindParentControlIncludingMe <ListBoxItem>(e.Source as DependencyObject);

                if (!dragSourceObject.HasItems)      // TreeViewItem must be a leaf
                {
                    if (bDrop)
                    {
                        dataProvider.Unparent();

                        ListBoxItem item = new ListBoxItem();
                        item.Content = dragSourceObject.Header;
                        item.ToolTip = dragSourceObject.ToolTip;
                        if (dropTarget == null)
                        {
                            dropContainer.Items.Add(item);
                        }
                        else
                        {
                            dropContainer.Items.Insert(dropContainer.Items.IndexOf(dropTarget), item);
                        }

                        item.IsSelected = true;
                        item.BringIntoView();
                    }
                    e.Effects = DragDropEffects.Move;
                    e.Handled = true;
                }
                else
                {
                    e.Effects = DragDropEffects.None;
                    e.Handled = true;
                }
            }
        }
Beispiel #9
0
        private void UpdateHighlightedItem(ListBoxItem newItem)
        {
            if (HighlightedItem == newItem)
            {
                return;
            }

            // Unselect old value.
            if (HighlightedItem != null)
            {
                HighlightedItem.IsSelected = false;
            }

            HighlightedItem = newItem;

            // Select new value.
            if (HighlightedItem != null)
            {
                HighlightedItem.IsSelected = true;
                HighlightedItem.BringIntoView();
            }
        }
        // Key navigation functions as bubbling scheme:
        // Category(CategoryListView) <- CategoryContent(StackPanel) <-
        // <- SubClasses(SubCategoryListView) OR MemberGroups(MemberGroupsListBox)
        // When element can't move further, it notifies its' parent about that.
        // And then parent decides what to do with it.

        private void UpdateHighlightedItem(ListBoxItem newItem)
        {
            if (HighlightedItem == newItem)
            {
                return;
            }

            // Unselect old value.
            if (HighlightedItem != null)
            {
                HighlightedItem.IsSelected = false;
            }

            HighlightedItem = newItem;

            // Select new value.
            if (HighlightedItem != null)
            {
                HighlightedItem.IsSelected = true;
                // If HighlightedItem is not visible for user, bring it and 5 next items into view.
                HighlightedItem.BringIntoView(new Rect(0, 0, 0, HighlightedItem.ActualHeight * 5));
                ShowTooltip(HighlightedItem);
            }
        }
Beispiel #11
0
        /// <summary>
        /// 搜索条件更改回调
        /// </summary>
        /// <param name="d"></param>
        /// <param name="e"></param>
        private static void OnSearchTextPropretyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            SearchableTextBox stb = d as SearchableTextBox;

            if (stb == null || !stb._canSearching)
            {
                return;
            }

            string searchKey = e.NewValue as string;

            if (string.IsNullOrEmpty(searchKey))//搜索关键字为空,不展示搜索popup
            {
                if (stb._popup != null)
                {
                    stb._popup.IsOpen = false;
                }

                return;
            }

            if (stb.SearchItemsSource == null || stb.SearchItemsSource.Count == 0)//搜索源为空,显示无搜索结果
            {
                if (stb._popup != null)
                {
                    stb._popup.IsOpen = true;
                }

                if (stb._lstSearchResult != null)
                {
                    stb._lstSearchResult.Visibility = Visibility.Collapsed;
                }

                return;
            }

            //根据关键字搜索匹配
            IList <SearchModel> searchResultList = null;

            if (stb.SearchMethod != null)
            {
                searchResultList = stb.SearchMethod(searchKey, stb.SearchItemsSource);
            }
            else
            {
                searchResultList = stb.DefaultSearch(searchKey, stb.SearchItemsSource);
            }

            lock (stb)
            {
                stb.SearchResultCollection.Clear();
                if (searchResultList != null && searchResultList.Count > 0)
                {
                    foreach (SearchModel sm in searchResultList)
                    {
                        stb.SearchResultCollection.Add(sm);
                    }
                }

                if (stb._popup != null)
                {
                    stb._popup.IsOpen = true;
                }

                if (stb._lstSearchResult != null)
                {
                    if (stb.SearchResultCollection.Count != 0)
                    {
                        stb._lstSearchResult.Visibility = Visibility.Visible;

                        //每次重新搜索,从头开始展示
                        VirtualizingPanel virtualizingPanel = stb._lstSearchResult.GetItemsHost() as VirtualizingPanel;
                        if (virtualizingPanel != null)
                        {
                            virtualizingPanel.CallEnsureGenerator();
                            virtualizingPanel.CallBringIndexIntoView(0);
                        }

                        ListBoxItem firstItem = (ListBoxItem)stb._lstSearchResult.ItemContainerGenerator.ContainerFromIndex(0);
                        if (null != firstItem)
                        {
                            firstItem.UpdateLayout();
                            firstItem.BringIntoView();
                        }
                    }
                    else
                    {
                        stb._lstSearchResult.Visibility = Visibility.Collapsed;
                    }
                }
            }
        }
        /// <summary>
        /// First determine whether the drag data is supported.
        /// Second determine what type the container is.
        /// Third determine what operation to do (only copy is supported).
        /// And finally handle the actual drop when <code>bDrop</code> is true.
        /// </summary>
        /// <param name="bDrop">True to perform an actual drop, otherwise just return e.Effects</param>
        /// <param name="sender">DragDrop event <code>sender</code></param>
        /// <param name="e">DragDrop event arguments</param>
        private void DragOverOrDrop(bool bDrop, object sender, DragEventArgs e)
        {
            string[] files = this.GetData(e) as string[];
            if (files != null)
            {
                e.Effects = DragDropEffects.None;
                ItemsControl dstItemsControl = sender as ItemsControl;  // 'sender' is used when dropped in an empty area
                if (dstItemsControl != null)
                {
                    foreach (string file in files)
                    {
                        if (sender is TabControl)
                        {
                            if (bDrop)
                            {
                                TabItem item = new TabItem();
                                item.Header  = System.IO.Path.GetFileName(file);
                                item.ToolTip = file;
                                dstItemsControl.Items.Insert(0, item);
                                item.IsSelected = true;
                            }
                            e.Effects = DragDropEffects.Copy;
                        }
                        else if (sender is ListBox)
                        {
                            if (bDrop)
                            {
                                ListBoxItem dstItem = Utilities.FindParentControlIncludingMe <ListBoxItem>(e.Source as DependencyObject);
                                ListBoxItem item    = new ListBoxItem();
                                item.Content = System.IO.Path.GetFileName(file);
                                item.ToolTip = file;
                                if (dstItem == null)
                                {
                                    dstItemsControl.Items.Add(item);    // ... if dropped on an empty area
                                }
                                else
                                {
                                    dstItemsControl.Items.Insert(dstItemsControl.Items.IndexOf(dstItem), item);
                                }

                                item.IsSelected = true;
                                item.BringIntoView();
                            }
                            e.Effects = DragDropEffects.Copy;
                        }
                        else if (sender is TreeView)
                        {
                            if (bDrop)
                            {
                                if (e.Source is ItemsControl)
                                {
                                    dstItemsControl = e.Source as ItemsControl; // Dropped on a TreeViewItem
                                }
                                TreeViewItem item = new TreeViewItem();
                                item.Header  = System.IO.Path.GetFileName(file);
                                item.ToolTip = file;
                                dstItemsControl.Items.Add(item);
                                item.IsSelected = true;
                                item.BringIntoView();
                            }
                            e.Effects = DragDropEffects.Copy;
                        }
                        else
                        {
                            throw new NotSupportedException("The item type is not implemented");
                        }
                        // No need to loop through multiple
                        // files if we're not dropping them
                        if (!bDrop)
                        {
                            break;
                        }
                    }
                }
                e.Handled = true;
            }
        }
Beispiel #13
0
        protected override void OnPreviewKeyDown(KeyEventArgs e)
        {
            if (txtAutoComplete.Text == "")
            {
                _currentItemIndex = -1;
                txtEntered        = "";
            }
            if (e.Key == Key.Back)
            {
                _currentItemIndex = -1;
                //var output = input.Substring(0, input.Length - 1);
                if (txtEntered != "")
                {
                    txtEntered = txtEntered.Substring(0, txtEntered.Length - 1);
                }
            }
            if (e.Key == Key.Delete)
            {
                txtEntered = txtAutoComplete.Text;
            }
            if (e.Key != Key.Down && e.Key != Key.Up)
            {
                char c = '\0';
                // txtEntered = txtAutoComplete.Text;
                bool capslock = Console.CapsLock;
                System.Windows.Input.Key key = e.Key;
                if (((e.Key == Key.LeftShift) || (e.Key == Key.RightShift)))
                {
                    __shiftPressed = true;
                    e.Handled      = true;
                }
                if ((key >= Key.A) && (key <= Key.Z))
                {
                    if (__shiftPressed || capslock)
                    {
                        c              = (char)((int)'A' + (int)(key - Key.A));
                        txtEntered    += Convert.ToString(c);
                        __shiftPressed = false;
                    }
                    else
                    {
                        if ((key >= Key.A) && (key <= Key.Z))
                        {
                            c           = (char)((int)'a' + (int)(key - Key.A));
                            txtEntered += Convert.ToString(c);
                        }
                    }
                }
                if ((key >= Key.D0) && (key <= Key.D9))
                {
                    c           = (char)((int)'0' + (int)(key - Key.D0));
                    txtEntered += Convert.ToString(c);
                }
                if ((key >= Key.NumPad0) && (key <= Key.NumPad9))
                {
                    c           = (char)((int)'0' + (int)(key - Key.NumPad0));
                    txtEntered += Convert.ToString(c);
                }
            }
            if (e.Key == Key.Up || e.Key == Key.Down)
            {
                if (txtAutoComplete.Text == "")
                {
                    lstData.SelectedIndex = 0;
                    return;
                }

                if (e.Key == Key.Up)
                {
                    if (lstData.Visibility == Visibility.Hidden || txtAutoComplete.IsFocused)
                    {
                        return;
                    }
                    _currentItemIndex -= 1;
                    if (_currentItemIndex < 0)
                    {
                        TextToChanged = txtEntered;
                        txtAutoComplete.Focus();
                        txtAutoComplete.CaretIndex = txtAutoComplete.Text.Length;
                        //_currentItemIndex = lstData.Items.Count - 1;
                    }
                }
                else if (e.Key == Key.Down)
                {
                    if (lstData.Visibility == Visibility.Hidden)
                    {
                        return;
                    }
                    if (_currentItemIndex == -1)
                    {
                        lstData.SelectedIndex = 0;
                    }
                    _currentItemIndex += 1;
                    if (_currentItemIndex > lstData.Items.Count - 1)
                    {
                        _currentItemIndex = 0;
                    }
                }
                if (_currentItemIndex < lstData.Items.Count && _currentItemIndex >= 0)
                {
                    currentItem = (ListBoxItem)lstData.ItemContainerGenerator.ContainerFromIndex(_currentItemIndex);
                    if (currentItem != null)
                    {
                        currentItem.Focus();
                        //currentItem.Background = (Brush)colorConverter.ConvertFromString(_selectedRowColor);
                        currentItem.BringIntoView();
                        TextToChanged = Convert.ToString(currentItem.Content);
                    }
                }
                e.Handled = true;
                return;
            }
            else if (e.Key == Key.Enter)
            {
                if (_currentItemIndex > -1)
                {
                    lstData.Visibility   = Visibility.Hidden;
                    lstData.SelectedItem = lstData.Items[_currentItemIndex];
                    _currentItemIndex    = -1;
                    txtAutoComplete.Focus();
                    txtAutoComplete.CaretIndex = txtAutoComplete.Text.Length;
                    txtEntered = Convert.ToString(currentItem.Content);
                }
            }
            base.OnPreviewKeyDown(e);
        }
Beispiel #14
0
        private void ResizeItemsInternal()
        {
            IEnumerable <ElasticListBoxItem> listBoxItems = this.Items
                                                            .Cast <object>()
                                                            .Select(x => this.ItemContainerGenerator.ContainerFromItem(x))
                                                            .Where(x => x != null)
                                                            .Cast <ElasticListBoxItem>();

            double totalHeight           = this.ActualHeight - this.Padding.Top - this.Padding.Bottom;
            bool   resetAll              = listBoxItems.Any(x => x.ActualHeight == 0);
            double totalCalculatedHeight = 0;

            foreach (ElasticListBoxItem listBoxItem in listBoxItems)
            {
                double height = 0;

                listBoxItem.MinHeight = 0;

                if (listBoxItem.IsHighlighted)
                {
                    double nonHighlightedHeight = listBoxItems.Where(x => !x.IsHighlighted).Sum(x => x.MinDisabledHeight);
                    double highlightedHeight    = listBoxItems.Where(x => x.IsHighlighted).Sum(x => x.MinEnabledHeight);

                    if (double.IsInfinity(listBoxItem.MaxHeight))
                    {
                        height = ((totalHeight - nonHighlightedHeight - highlightedHeight) * listBoxItem.Percentage) + listBoxItem.MinEnabledHeight;
                        if (height <= listBoxItem.MinEnabledHeight)
                        {
                            listBoxItem.MinHeight  = listBoxItem.MinEnabledHeight;
                            totalCalculatedHeight += listBoxItem.MinEnabledHeight;
                        }
                        else
                        {
                            totalCalculatedHeight += height;
                        }
                    }
                    else
                    {
                        height = ((listBoxItem.MaxHeight - nonHighlightedHeight - highlightedHeight) * listBoxItem.Percentage) + listBoxItem.MinEnabledHeight;
                        if (height <= listBoxItem.MinEnabledHeight)
                        {
                            listBoxItem.MinHeight  = listBoxItem.MinEnabledHeight;
                            totalCalculatedHeight += listBoxItem.MinEnabledHeight;
                        }
                        else
                        {
                            totalCalculatedHeight += height;
                        }
                    }
                }
                else
                {
                    height = listBoxItem.MinDisabledHeight;
                    listBoxItem.MinHeight = listBoxItem.MinDisabledHeight;

                    totalCalculatedHeight += height;
                }

                if ((listBoxItem.ActualHeight != height) && (height > 0))
                {
                    if (resetAll)
                    {
                        listBoxItem.Height = height;
                    }
                    else
                    {
                        Storyboard storyboard = new Storyboard();

                        DoubleAnimation doubleAnimation = new DoubleAnimation(
                            listBoxItem.ActualHeight,
                            height,
                            this.ResizeDuration)
                        {
                            EasingFunction = new QuarticEase()
                        };
                        Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath(ElasticListBox.HeightProperty));
                        storyboard.Children.Add(doubleAnimation);
                        storyboard.Completed += (sender, e) =>
                        {
                            // Scroll to the first highlighted item if the user has not got his mouse over the list box.
                            ListBoxItem firstListBoxItem = listBoxItems.FirstOrDefault(x => x.IsHighlighted);
                            if ((firstListBoxItem != null) && !this.IsMouseOver)
                            {
                                firstListBoxItem.BringIntoView();
                            }
                        };
                        storyboard.Begin(listBoxItem);
                    }
                }
            }

            if (totalCalculatedHeight > this.ActualHeight)
            {
                ScrollViewer.SetVerticalScrollBarVisibility(this, ScrollBarVisibility.Auto);
            }
            else
            {
                ScrollViewer.SetVerticalScrollBarVisibility(this, ScrollBarVisibility.Disabled);
            }
        }