Exemplo n.º 1
0
        public override void Update(ITimeService time)
        {
            var controlArray = TreeTraversal.PreOrderVisit(Content).ToArray();

            for (int i = 1; i < controlArray.Length; i++)
            {
                var control = controlArray[i];
                control.Update(time);
            }
        }
Exemplo n.º 2
0
 public UIElement Find(string id)
 {
     foreach (UIElement ctl in TreeTraversal.PreOrderVisit(this).Skip(1))
     {
         if (ctl.Name == id)
         {
             return(ctl);
         }
     }
     return(null);
 }
Exemplo n.º 3
0
 protected override void Dispose(bool disposeManagedResources)
 {
     base.Dispose(disposeManagedResources);
     if (disposeManagedResources)
     {
         foreach (UIElement uiElement in TreeTraversal.PreOrderVisit(Content))
         {
             uiElement.Dispose();
         }
     }
     IsInited = false;
 }
Exemplo n.º 4
0
        private void PopulateItems()
        {
            if (ItemsSource == null)
            {
                return;
            }

            if (ItemTemplate.DataType != null && !ReflectionHelper.IsTypeDerived(ItemTemplate.DataType, GetType()))
            {
                LogEvent.UserInterface.Warning(string.Format("ItemTemplate '{0}' expects type {1}. Element '{2}' is of type {3}",
                                                             ItemTemplate.Key, ItemTemplate.DataType.Name, Name, GetType().Name));
                return;
            }

            int itemCount = 1;

            foreach (var item in ItemsSource)
            {
                UIElement previousElement = this;
                foreach (UIElement element in TreeTraversal.PreOrderVisit(ItemTemplate.VisualTree))
                {
                    UIElement newItem = ToDispose(element.Copy());

                    if (element.Parent is ContentControl)
                    {
                        ((ContentControl)previousElement).Content = newItem;
                    }
                    else
                    {
                        container.Add(newItem);
                    }

                    newItem.DataContext = item;

                    foreach (var kvp in ItemTemplate.Bindings.Where(kvp => string.Equals(newItem.Name, kvp.Value.TargetElement)))
                    {
                        newItem.SetBinding(kvp.Value, kvp.Key);
                    }

                    newItem.Name = string.Format("{0}{1:D2}", newItem.Name, itemCount++);

                    previousElement = newItem;
                }
            }
        }
Exemplo n.º 5
0
        private void CreateContainer()
        {
            Contract.Requires <InvalidOperationException>(ItemTemplate.VisualTree is Panel, "VisualTree root must be a Panel");
            var panel = (Panel)ToDispose(ItemsPanelTemplate.VisualTree.Copy());

            if (panel.IsItemsHost)
            {
                container = panel;
            }
            else
            {
                foreach (var child in TreeTraversal.PreOrderVisit(panel))
                {
                    var childPanel = child as Panel;

                    if (childPanel != null && childPanel.IsItemsHost)
                    {
                        container = childPanel;
                        break;
                    }
                }
            }

            foreach (var kvp in ItemsPanelTemplate.Bindings)
            {
                var target = panel.Find(kvp.Value.TargetElement);
                if (target != null)
                {
                    target.DataContext = DataContext;
                    target.SetBinding(kvp.Value, kvp.Key);
                    break;
                }
            }

            if (container == null)
            {
                container = panel;
            }

            Children.Add(panel);
        }
Exemplo n.º 6
0
 protected override TResource GetResource <TResource>(string resourceName)
 {
     return(TreeTraversal.PreOrderVisit(Content).First(c => string.Equals(c.Name, resourceName)) as TResource);
 }
Exemplo n.º 7
0
 protected override bool ContainsResource(string resourceName)
 {
     return(TreeTraversal.PreOrderVisit(Content).Any(c => string.Equals(c.Name, resourceName)));
 }