Ejemplo n.º 1
0
        /// <summary>
        /// Search this node and its siblings+children for an ANamable matching the name and type T
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="name"></param>
        /// <returns></returns>
        private T MineByName <T>(string name) where T : ANamable
        {
            if (Name.Equals(name))
            {
                return(this as T);
            }

            IParent parent = this as IParent;

            if (parent != null)
            {
                return((from c in parent.GetChildren()
                        let d = c.MineByName <T>(name)
                                where d != null
                                select d).FirstOrDefault());
            }

            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Search this node and its siblings+children for ANamables that have a common base type T
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        private IEnumerable <T> MyInventoryByBase <T>() where T : ANamable
        {
            var mine   = new List <T>();
            T   myself = this as T;

            if (myself != null)
            {
                mine.Add(myself);
            }

            IParent parent = this as IParent;

            if (parent != null)
            {
                mine.AddRange(parent.GetChildren().SelectMany(x => x.MyInventoryByBase <T>()));
            }

            return(mine);
        }
Ejemplo n.º 3
0
        private static void OnIsCheckedPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            IParent <object> sect   = d as IParent <object>;
            DependencyObject depObj = d;

            if (sect != null)
            {
                if (((bool?)e.NewValue).HasValue)
                {
                    foreach (DependencyObject p in sect.GetChildren())
                    {
                        SetIsChecked(p, (bool?)e.NewValue);
                    }
                }
            }

            if (depObj != null)
            {
                var parentObject           = depObj.GetValue(ParentProperty) as IParent <object>;
                var parentDependencyObject = depObj.GetValue(ParentProperty) as DependencyObject;
                int ch = parentObject?.GetChildren()?.Where(x => GetIsChecked(x as DependencyObject) == true).Count() ?? 0;
                int un = parentObject?.GetChildren()?.Where(x => GetIsChecked(x as DependencyObject) == false).Count() ?? 0;
                if ((un > 0) && (ch > 0))
                {
                    SetIsChecked(parentDependencyObject, null);
                    return;
                }

                if (ch > 0)
                {
                    SetIsChecked(parentDependencyObject, true);
                    return;
                }

                SetIsChecked(parentDependencyObject, false);
            }
        }