/// <summary> /// Removes an entry from the item-container dictionary. /// </summary> /// <param name="element">The item container.</param> /// <param name="item">The text item.</param> protected override void ClearContainerForItemOverride(DependencyObject element, object item) { base.ClearContainerForItemOverride(element, item); DecoratorTextBoxItem textItem = (DecoratorTextBoxItem)item; DecoratorItemContainer container = (DecoratorItemContainer)element; this.containers.Remove(container); if (textItem != null && this.containersByItem.ContainsKey(textItem)) { this.containersByItem.Remove(textItem); } }
/// <summary> /// Sets up the bindings for whether a term is encodable or not, and stores /// in the item-container dictionary. /// </summary> /// <param name="element">The decorator container.</param> /// <param name="item">The text item.</param> protected override void PrepareContainerForItemOverride(DependencyObject element, object item) { base.PrepareContainerForItemOverride(element, item); DecoratorItemContainer container = (DecoratorItemContainer)element; DecoratorTextBoxItem textItem = (DecoratorTextBoxItem)item; this.containersByItem.Add(textItem, container); container.DataContext = textItem; container.SetBinding(DecoratorItemContainer.IsEncodableProperty, new System.Windows.Data.Binding("IsEncodable")); container.SetBinding(DecoratorItemContainer.IsEncodedProperty, new System.Windows.Data.Binding("IsEncoded")); container.SetBinding(DecoratorItemContainer.ContainerPositionProperty, new System.Windows.Data.Binding("ContainerPosition")); container.SetBinding(DecoratorItemContainer.IsMouseHighlightedProperty, new System.Windows.Data.Binding("IsMouseHighlighted")); container.SetBinding(DecoratorItemContainer.IsFocusHighlightedProperty, new System.Windows.Data.Binding("IsFocusHighlighted")); }
/// <summary> /// Generates a DecoratorItemContainer with template. /// </summary> /// <returns>A decorator item container.</returns> protected override DependencyObject GetContainerForItemOverride() { DecoratorItemContainer container = new DecoratorItemContainer(); if (this.DecoratorItemContainerStyle != null) { container.Style = this.DecoratorItemContainerStyle; } if (this.containers.Count > 0) { container.Top = this.containers[containers.Count - 1].Top + this.containers[this.containers.Count - 1].ActualHeight; } this.containers.Add(container); return(container); }
/// <summary> /// Updates the scroll viewer position. /// </summary> /// <param name="index">The current item index.</param> private void UpdateScrollViewer(int index) { if (index < this.textBoxItems.Count) { DecoratorItemContainer container = this.decoratorItemsControl.GetContainerFromItem(this.textBoxItems[index]); if (container != null && this.scrollViewer != null) { if (this.scrollViewer.VerticalOffset > container.Top) { this.scrollViewer.ScrollToVerticalOffset(container.Top - 5); } else if (this.scrollViewer.VerticalOffset + this.scrollViewer.ViewportHeight < container.Top + container.ActualHeight) { this.scrollViewer.ScrollToVerticalOffset( container.Top + container.ActualHeight - this.scrollViewer.ViewportHeight + 5); } } } }
/// <summary> /// Generates a DecoratorItemContainer with template. /// </summary> /// <returns>A decorator item container.</returns> protected override DependencyObject GetContainerForItemOverride() { DecoratorItemContainer container = new DecoratorItemContainer(); if (this.DecoratorItemContainerStyle != null) { container.Style = this.DecoratorItemContainerStyle; } if (this.containers.Count > 0) { container.Top = this.containers[containers.Count - 1].Top + this.containers[this.containers.Count - 1].ActualHeight; } this.containers.Add(container); return container; }
/// <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) { DecoratorItemContainer container = (DecoratorItemContainer)dependencyObject; container.UpdateVisualState(true); }