/// <inheritdoc/>
        protected override void OnContainersDematerialized(ItemContainerEventArgs e)
        {
            base.OnContainersDematerialized(e);

            var panel = (InputElement)Presenter.Panel;

            foreach (var container in e.Containers)
            {
                if (KeyboardNavigation.GetTabOnceActiveElement(panel) == container.ContainerControl)
                {
                    KeyboardNavigation.SetTabOnceActiveElement(panel, null);
                    break;
                }
            }
        }
 protected override void OnContainersRecycled(ItemContainerEventArgs e)
 {
     foreach (var i in e.Containers)
     {
         if (i.ContainerControl != null && i.Item != null)
         {
             MarkContainerSelected(
                 i.ContainerControl,
                 SelectedItems.Contains(i.Item));
         }
     }
 }
Example #3
0
        /// <summary>
        /// Called when containers are recycled for the <see cref="ItemsControl"/> by its
        /// <see cref="ItemContainerGenerator"/>.
        /// </summary>
        /// <param name="e">The details of the containers.</param>
        protected virtual void OnContainersRecycled(ItemContainerEventArgs e)
        {
            var toRemove = new List<ILogical>();

            foreach (var container in e.Containers)
            {
                // If the item is its own container, then it will be removed from the logical tree
                // when it is removed from the Items collection.
                if (container?.ContainerControl != container?.Item)
                {
                    toRemove.Add(container.ContainerControl);
                }
            }

            LogicalChildren.RemoveAll(toRemove);
        }
        /// <inheritdoc/>
        protected override void OnContainersMaterialized(ItemContainerEventArgs e)
        {
            base.OnContainersMaterialized(e);

            var selectedIndex = SelectedIndex;
            var selectedContainer = e.Containers
                .FirstOrDefault(x => (x.ContainerControl as ISelectable)?.IsSelected == true);

            if (selectedContainer != null)
            {
                SelectedIndex = selectedContainer.Index;
            }
            else if (selectedIndex >= e.StartingIndex &&
                     selectedIndex < e.StartingIndex + e.Containers.Count)
            {
                var container = e.Containers[selectedIndex - e.StartingIndex];

                if (container.ContainerControl != null)
                {
                    MarkContainerSelected(container.ContainerControl, true);
                }
            }
        }
 /// <summary>
 /// Raises the <see cref="Recycled"/> event.
 /// </summary>
 /// <param name="e">The event args.</param>
 protected void RaiseRecycled(ItemContainerEventArgs e)
 {
     Recycled?.Invoke(this, e);
 }
Example #6
0
        /// <summary>
        /// Called when new containers are materialized for the <see cref="ItemsControl"/> by its
        /// <see cref="ItemContainerGenerator"/>.
        /// </summary>
        /// <param name="e">The details of the containers.</param>
        protected virtual void OnContainersMaterialized(ItemContainerEventArgs e)
        {
            var toAdd = new List<ILogical>();

            foreach (var container in e.Containers)
            {
                // If the item is its own container, then it will be added to the logical tree when
                // it was added to the Items collection.
                if (container.ContainerControl != null && container.ContainerControl != container.Item)
                {
                    toAdd.Add(container.ContainerControl);
                }
            }

            LogicalChildren.AddRange(toAdd);
        }
Example #7
0
        /// <summary>
        /// Called when a new item container is materialized, to set its selected state.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event args.</param>
        private void ContainerMaterialized(object sender, ItemContainerEventArgs e)
        {
            var selectedItem = SelectedItem;

            if (selectedItem != null)
            {
                foreach (var container in e.Containers)
                {
                    if (container.Item == selectedItem)
                    {
                        ((TreeViewItem)container.ContainerControl).IsSelected = true;

                        if (AutoScrollToSelectedItem)
                        {
                            DispatcherTimer.RunOnce(
                                container.ContainerControl.BringIntoView,
                                TimeSpan.Zero);
                        }

                        break;
                    }
                }
            }
        }
 /// <summary>
 /// Raises the <see cref="Recycled"/> event.
 /// </summary>
 /// <param name="e">The event args.</param>
 protected void RaiseRecycled(ItemContainerEventArgs e)
 {
     Recycled?.Invoke(this, e);
 }
Example #9
0
        /// <summary>
        /// Called when containers are dematerialized for the <see cref="ItemsControl"/> by its
        /// <see cref="ItemContainerGenerator"/>.
        /// </summary>
        /// <param name="e">The details of the containers.</param>
        protected virtual void OnContainersDematerialized(ItemContainerEventArgs e)
        {
            foreach (var container in e.Containers)
            {
                // If the item is its own container, then it will be removed from the logical tree
                // when it is removed from the Items collection.
                if (container?.ContainerControl != container?.Item)
                {
                    if (ItemContainerGenerator.ContainerType == null)
                    {
                        var containerControl = container.ContainerControl as ContentPresenter;

                        if (containerControl != null)
                        {
                            ((ISetLogicalParent)containerControl).SetParent(null);

                            if (containerControl.Child != null)
                            {
                                LogicalChildren.Remove(containerControl.Child);
                            }
                        }
                    }
                    else
                    {
                        LogicalChildren.Remove(container.ContainerControl);
                    }
                }
            }
        }
Example #10
0
        /// <summary>
        /// Called when new containers are materialized for the <see cref="ItemsControl"/> by its
        /// <see cref="ItemContainerGenerator"/>.
        /// </summary>
        /// <param name="e">The details of the containers.</param>
        protected virtual void OnContainersMaterialized(ItemContainerEventArgs e)
        {
            foreach (var container in e.Containers)
            {
                // If the item is its own container, then it will be added to the logical tree when
                // it was added to the Items collection.
                if (container.ContainerControl != null && container.ContainerControl != container.Item)
                {
                    if (ItemContainerGenerator.ContainerType == null)
                    {
                        var containerControl = container.ContainerControl as ContentPresenter;

                        if (containerControl != null)
                        {
                            ((ISetLogicalParent)containerControl).SetParent(this);
                            containerControl.SetValue(TemplatedParentProperty, null);

                            containerControl.UpdateChild();

                            if (containerControl.Child != null)
                            {
                                LogicalChildren.Add(containerControl.Child);
                            }
                        }
                    }
                    else
                    {
                        LogicalChildren.Add(container.ContainerControl);
                    }
                }
            }
        }
Example #11
0
 private void TreeViewItemMaterialized(object sender, ItemContainerEventArgs e)
 {
     var item = (TreeViewItem)e.Containers[0].ContainerControl;
     item.TemplateApplied += TreeViewItemTemplateApplied;
 }