Exemple #1
0
 public static IEnumerable <DependencyObject> Child(this DependencyObject dependencyObject, DependencyObject exclude = null)
 {
     foreach (var item in LogicalTreeHelper.GetChildren(dependencyObject).OfType <DependencyObject>())
     {
         if (item != exclude)
         {
             yield return(item);
         }
     }
     foreach (var item in LogicalTreeHelper.GetChildren(dependencyObject).OfType <DependencyObject>())
     {
         if (item != exclude)
         {
             foreach (var result in item.Child())
             {
                 yield return(result);
             }
         }
     }
 }
        /// <summary>
        ///     Evaluate the HasLoadedChangeHandler flag on the given node by
        ///   querying its children, and styles, and templates.
        /// </summary>
        /// <param name="fo">
        ///     Node
        /// </param>
        private static bool AreThereLoadedChangeHandlersInSubtree(ref FrameworkObject fo)
        {
            // HasHandler flag can be evaluated only for a FE/FCE.
            if (!fo.IsValid)
            {
                return(false);
            }

            if (fo.ThisHasLoadedChangeEventHandler)
            {
                return(true);
            }

            if (fo.IsFE)
            {
                // Check if any of your visual children have the flag set
                Visual v     = (Visual)fo.FE;
                int    count = VisualTreeHelper.GetChildrenCount(v);

                for (int i = 0; i < count; i++)
                {
                    FrameworkElement child = VisualTreeHelper.GetChild(v, i) as FrameworkElement;
                    if (child != null && child.SubtreeHasLoadedChangeHandler)
                    {
                        return(true);
                    }
                }
            }

            // Check if any of your logical children have the flag set
            foreach (object o in LogicalTreeHelper.GetChildren(fo.DO))
            {
                DependencyObject child = o as DependencyObject;
                if (null != child && SubtreeHasLoadedChangeHandlerHelper(child))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #3
0
            private bool isChildOf(IChangeNotifer ch, DO p)
            {
                if (ch is DO dch)
                {
                    if (H.GetParent(dch) == p)
                    {
                        return(true);
                    }
                    child.MODIFIED -= reset; isTracking = false;
                    return(false);
                }
                var chs = H.GetChildren(p);

                foreach (var c in chs)
                {
                    if (c == ch)
                    {
                        return(true);
                    }
                }
                child.MODIFIED -= reset; isTracking = false;
                return(false);
            }
Exemple #4
0
        private void bind(FE parent, int dl = 0)
        {
            if (parent == null || dl > searchDepth)
            {
                return;
            }
            var chs = H.GetChildren(parent);

            foreach (object ch in chs)
            {
                if (ch is UIReseter r && r != this)
                {
                    throw new Exception($@"There's overlapping ""{nameof(UIReseter)}"" instance in the tree. Use single global instance of check ""{nameof(UIReseter.searchDepth)}"" levels.");
                }
                if (ch is IChangeNotifer sc)
                {
                    trackObject(sc, parent);
                }
                else
                {
                    bind(ch as FE, ++dl);
                }
            }
        }
Exemple #5
0
 public static IEnumerable <DependencyObject> GetLogicalChilds([CanBeNull] this DependencyObject obj) => obj is null
     ? Enumerable.Empty <DependencyObject>()
     : LogicalTreeHelper.GetChildren(obj).OfType <DependencyObject>();
        public void CreateFriendsList()
        {
            var friend_list = MainWindow.api.Friends.Get(new FriendsGetParams
            {
                Order    = FriendsOrder.Hints,
                Fields   = ProfileFields.FirstName | ProfileFields.Photo50,
                Count    = 6000,
                NameCase = NameCase.Nom,
            });

            /*_ = Dispatcher.BeginInvoke(DispatcherPriority.Render, new ThreadStart(delegate
             *  {
             *      FullFriendList.Items.Add(MainWindow.api.Account.GetProfileInfo().FirstName + ' ' + MainWindow.api.Account.GetProfileInfo().LastName + " ID:" + MainWindow.api.UserId);
             *  }));*/
            int friendnum = 0;

            foreach (var friend in friend_list)
            {
                using (WebClient webClient = new WebClient())
                {
                    try
                    {
                        webClient.DownloadFile(friend.Photo50.AbsoluteUri, (Path.Combine(Environment.CurrentDirectory, "Friendava" + friendnum.ToString() + ".jpg")));
                    }
                    catch { }
                }
                Dispatcher.BeginInvoke(new ThreadStart(delegate {
                    ListBoxItem itemfriend = new ListBoxItem(); itemfriend.Name = "frienditem" + friendnum.ToString();
                    StackPanel itemstack   = new StackPanel(); itemstack.Name = "friendstack" + friendnum.ToString();
                    Grid itemgrid          = new Grid(); for (int i = 0; i < 8; i++)
                    {
                        itemgrid.ColumnDefinitions.Add(new ColumnDefinition());
                    }
                    for (int i = 0; i < 3; i++)
                    {
                        itemgrid.RowDefinitions.Add(new RowDefinition());
                    }
                    itemgrid.Name = "friendgrid" + friendnum.ToString();
                    itemstack.Children.Add(itemgrid);
                    TextBlock friendinfo = new TextBlock(); friendinfo.Text = "  " + friend.FirstName + " " + friend.LastName;
                    friendinfo.FontSize  = 15;
                    Grid.SetColumn(friendinfo, 5); Grid.SetColumnSpan(friendinfo, 4);
                    Grid.SetRow(friendinfo, 1); Grid.SetRowSpan(friendinfo, 2);
                    itemgrid.Children.Add(friendinfo);
                    itemfriend.Content = itemstack;
                    itemfriend.Tag     = friend.Id;
                    FullFriendList.Items.Add(itemfriend); FullFriendList.UpdateLayout();
                }));
                friendnum++;
            }

            _ = Dispatcher.BeginInvoke(new ThreadStart(delegate
            {
                int num = 0;
                System.Collections.IEnumerable nodes = LTH.GetChildren(FullFriendList);
                foreach (var node in nodes)
                {
                    //MessageBox.Show(node.GetType().ToString());
                    if (node is string)
                    {
                        continue;
                    }
                    Visual listitem = (Visual)node;
                    System.Collections.IEnumerable items = LTH.GetChildren(listitem);
                    foreach (var item in items)
                    {
                        if (item is StackPanel)
                        {
                            Grid frgr             = VTH.GetChild(item as DependencyObject, 0) as Grid;
                            ImageBrush friendava  = new ImageBrush();
                            BitmapImage friendbit = new BitmapImage(new Uri(Path.Combine(Environment.CurrentDirectory, "Friendava" + num.ToString() + ".jpg")));
                            friendava.ImageSource = friendbit;
                            Ellipse ava           = new Ellipse();
                            ava.Height            = 50;
                            ava.Width             = 50;
                            ava.Fill = friendava;
                            Grid.SetColumn(ava, 0); Grid.SetColumnSpan(ava, 2);
                            Grid.SetRow(ava, 0); Grid.SetRowSpan(ava, 3);
                            frgr.Children.Add(ava);
                        }
                    }
                    num++;
                }
            }));
        }