示例#1
0
        private static bool NoVisibleSiblingExists(List <DependencyObject> children)
        {
            foreach (DependencyObject Child in children)
            {
                if (AutoSeparator.IsVisible(Child))
                {
                    return(false);
                }
            }

            return(true);
        }
示例#2
0
 private static bool SeparatorAlreadyThere(List <DependencyObject> children)
 {
     foreach (DependencyObject Child in children)
     {
         if (Child is Separator && AutoSeparator.IsVisible(Child))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     return(false);
 }
示例#3
0
        private void UpdateVisibility()
        {
            if (this.parent != null)
            {
                List <DependencyObject> PreviousChildren  = new List <DependencyObject>();
                List <DependencyObject> FollowingChildren = new List <DependencyObject>();

                bool FoundMyself = false;
                for (int Index = 0; Index < VisualTreeHelper.GetChildrenCount(this.parent); Index++)
                {
                    DependencyObject Child = VisualTreeHelper.GetChild(this.parent, Index);
                    // ReSharper disable once PossibleUnintendedReferenceComparison
                    if (Child == this)
                    {
                        FoundMyself = true;
                    }
                    else
                    {
                        if (FoundMyself)
                        {
                            FollowingChildren.Add(Child);
                        }
                        else
                        {
                            PreviousChildren.Add(Child);
                        }
                    }
                }

                PreviousChildren.Reverse();

                if (AutoSeparator.NoVisibleSiblingExists(PreviousChildren) || AutoSeparator.NoVisibleSiblingExists(FollowingChildren) || AutoSeparator.SeparatorAlreadyThere(FollowingChildren))
                {
                    this.Visibility = Visibility.Collapsed;
                }
                else
                {
                    this.Visibility = Visibility.Visible;
                }
            }
        }