Example #1
0
        /// <summary>
        /// Prepares the checkbox by creating bindings and hooking events.
        /// </summary>
        /// <param name="element">The container element.</param>
        /// <param name="item">The data item.</param>
        protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
        {
            base.PrepareContainerForItemOverride(element, item);

            MatchingTermItemContainer container = (MatchingTermItemContainer)element;

            if (this.ItemContainerStyle != null)
            {
                container.Style = this.ItemContainerStyle;
            }

            container.GotFocus                  += new RoutedEventHandler(this.Container_GotFocus);
            container.LostFocus                 += new RoutedEventHandler(this.Container_LostFocus);
            container.MouseEnter                += new MouseEventHandler(this.Container_MouseEnter);
            container.MouseLeave                += new MouseEventHandler(this.Container_MouseLeave);
            container.MouseEnterPopup           += new MouseEventHandler(this.Container_MouseEnter);
            container.MouseLeavePopup           += new MouseEventHandler(this.Container_MouseLeave);
            container.SelectionChanged          += new EventHandler(this.Container_SelectionChanged);
            container.PopupOpening              += new EventHandler(this.Container_PopupOpening);
            container.DataContext                = item;
            container.SelectedItemMemberPath     = this.SelectedItemMemberPath;
            container.AlternateItemsMemberPath   = this.AlternateItemsMemberPath;
            container.SelectedItemTextMemberPath = this.SelectedItemTextMemberPath;
            container.FlyOutContentTemplate      = this.FlyOutContentTemplate;
            container.EncodedItemTemplate        = this.EncodedItemTemplate;
            container.IsSelectedMemberPath       = this.IsSelectedMemberPath;

            System.Windows.Data.Binding lengthBinding = new System.Windows.Data.Binding(this.LengthMemberPath);
            lengthBinding.Mode = System.Windows.Data.BindingMode.TwoWay;
            container.SetBinding(MatchingTermItemContainer.SelectedItemTextLengthProperty, lengthBinding);

            this.containers.Add(container);
            this.containersByItem.Add(item, container);
        }
Example #2
0
        /// <summary>
        /// Unhooks the checkbox events before clearing the container.
        /// </summary>
        /// <param name="element">The container element.</param>
        /// <param name="item">The data item.</param>
        protected override void ClearContainerForItemOverride(DependencyObject element, object item)
        {
            base.ClearContainerForItemOverride(element, item);

            MatchingTermItemContainer container = (MatchingTermItemContainer)element;

            container.GotFocus         -= new RoutedEventHandler(this.Container_GotFocus);
            container.LostFocus        -= new RoutedEventHandler(this.Container_LostFocus);
            container.MouseEnter       -= new MouseEventHandler(this.Container_MouseEnter);
            container.MouseLeave       -= new MouseEventHandler(this.Container_MouseLeave);
            container.MouseEnterPopup  -= new MouseEventHandler(this.Container_MouseEnter);
            container.MouseLeavePopup  -= new MouseEventHandler(this.Container_MouseLeave);
            container.SelectionChanged -= new EventHandler(this.Container_SelectionChanged);
            container.PopupOpening     -= new EventHandler(this.Container_PopupOpening);

            this.containers.Remove(container);
            this.containersByItem.Remove(container.DataContext);
        }
Example #3
0
        /// <summary>
        /// Scrolls and item into view.
        /// </summary>
        /// <param name="item">The item to scroll into view.</param>
        public void ScrollIntoView(object item)
        {
            if (this.scrollViewer != null && this.containersByItem.ContainsKey(item))
            {
                MatchingTermItemContainer container = this.containersByItem[item];
                if (System.Windows.Media.VisualTreeHelper.GetParent(container) != null)
                {
                    System.Windows.Media.GeneralTransform transform = container.TransformToVisual(this.scrollViewer);
                    double verticalOffset = transform.Transform(new Point(0, 0)).Y;

                    if (verticalOffset + container.ActualHeight > this.scrollViewer.ViewportHeight)
                    {
                        this.scrollViewer.ScrollToVerticalOffset(this.scrollViewer.VerticalOffset + (verticalOffset - this.scrollViewer.ViewportHeight) + container.ActualHeight);
                    }
                    else if (verticalOffset < 0)
                    {
                        this.scrollViewer.ScrollToVerticalOffset(this.scrollViewer.VerticalOffset + verticalOffset);
                    }
                }
            }
        }
Example #4
0
        /// <summary>
        /// Updates the visual state of the control.
        /// </summary>
        /// <param name="dependencyObject">The instance of the container control.</param>
        /// <param name="args">Dependency Property Changed Event Args.</param>
        private static void OnStateChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
        {
            MatchingTermItemContainer container = (MatchingTermItemContainer)dependencyObject;

            container.UpdateVisualState(true);
        }
Example #5
0
        /// <summary>
        /// Updates the alternate items member path.
        /// </summary>
        /// <param name="dependencyObject">The MatchingTermItemContainer.</param>
        /// <param name="eventArgs">Dependency Property Changed Event Args.</param>
        private static void AlternateItemsMemberPath_Changed(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs eventArgs)
        {
            MatchingTermItemContainer container = (MatchingTermItemContainer)dependencyObject;

            container.UpdateAlternateItemsMemberPath();
        }
Example #6
0
        /// <summary>
        /// Generates a check box as the item container.
        /// </summary>
        /// <returns>A checkbox item container.</returns>
        protected override DependencyObject GetContainerForItemOverride()
        {
            MatchingTermItemContainer matchingTermItemContainer = new MatchingTermItemContainer();

            return(matchingTermItemContainer);
        }
Example #7
0
        /// <summary>
        /// Changes the text for a specific term.
        /// <para>
        /// This method uses the start index (from term item) to move through the decorator textbox
        /// items, and update the text in the item to show the new text. If the new text is longer,
        /// more text box items are inserted. If the new text is shorter, text box items are removed.
        /// </para>
        /// <para>
        /// The text box text is then updated with the change, flagging that the change is a programmatic
        /// change. And finally, each term item that comes after the changed item, has the start index
        /// updated with its new start position.
        /// </para>
        /// </summary>
        /// <param name="termContainer">The term container to update.</param>
        internal void ChangeText(MatchingTermItemContainer termContainer)
        {
            if (termContainer != null)
            {
                TermItem termItem = this.termItemsControl.GetContainerFromItem(termContainer.DataContext);
                if (termItem != null)
                {
                    if (this.textBox != null)
                    {
                        this.programaticTextChangeCount++;
                    }

                    int  count            = 0;
                    bool mouseHighlighted = false;
                    bool focusHighlighted = false;
                    for (int i = termItem.StartIndex; i < Math.Min(termItem.StartIndex + termItem.Length, termItem.StartIndex + termContainer.SelectedItemText.Length); i++)
                    {
                        if (i == termItem.StartIndex)
                        {
                            focusHighlighted = this.textBoxItems[i].IsFocusHighlighted;
                            mouseHighlighted = this.textBoxItems[i].IsMouseHighlighted;
                        }

                        this.textBoxItems[i].Text = termContainer.SelectedItemText[count].ToString(CultureInfo.CurrentCulture);
                        count++;
                    }

                    if (termItem.Length < termContainer.SelectedItemText.Length)
                    {
                        if (termItem.Length > 1)
                        {
                            this.textBoxItems[termItem.StartIndex + termItem.Length - 1].ContainerPosition = ContainerPosition.Middle;
                        }
                        else
                        {
                            this.textBoxItems[termItem.StartIndex].ContainerPosition = ContainerPosition.Start;
                        }

                        for (int i = termItem.StartIndex + termItem.Length; i < termItem.StartIndex + termContainer.SelectedItemText.Length; i++)
                        {
                            DecoratorTextBoxItem textBoxItem = new DecoratorTextBoxItem(termContainer.SelectedItemText[i - termItem.StartIndex].ToString(CultureInfo.CurrentCulture));
                            if (i == termItem.StartIndex + termContainer.SelectedItemText.Length - 1)
                            {
                                textBoxItem.ContainerPosition = ContainerPosition.End;
                            }
                            else
                            {
                                textBoxItem.ContainerPosition = ContainerPosition.Middle;
                            }

                            textBoxItem.IsFocusHighlighted = focusHighlighted;
                            textBoxItem.IsMouseHighlighted = mouseHighlighted;
                            textBoxItem.AddTermItem(termItem);
                            this.textBoxItems.Insert(i, textBoxItem);
                        }
                    }
                    else if (termItem.Length > termContainer.SelectedItemText.Length)
                    {
                        for (int i = termItem.StartIndex + termContainer.SelectedItemText.Length; i < termItem.StartIndex + termItem.Length; i++)
                        {
                            this.textBoxItems.RemoveAt(termItem.StartIndex + termContainer.SelectedItemText.Length);
                        }

                        if (termContainer.SelectedItemText.Length > 1)
                        {
                            this.textBoxItems[termItem.StartIndex + termContainer.SelectedItemText.Length - 1].ContainerPosition = ContainerPosition.End;
                        }
                        else
                        {
                            this.textBoxItems[termItem.StartIndex].ContainerPosition = ContainerPosition.Only;
                        }
                    }

                    if (this.textBox != null)
                    {
                        string newText = this.textBox.Text.Remove(termItem.StartIndex, termItem.Length);
                        newText           = newText.Insert(termItem.StartIndex, termContainer.SelectedItemText);
                        this.textBox.Text = newText;
                    }

                    foreach (TermItem item in this.termItemsControl.TermItems)
                    {
                        if (item.StartIndex > termItem.StartIndex)
                        {
                            item.StartIndex += termContainer.SelectedItemText.Length - termItem.Length;
                        }
                    }

                    termItem.Length = termContainer.SelectedItemText.Length;
                }
            }
        }