Beispiel #1
0
        public override Vector2 Measure()
        {
            if (Size.HasValue)
                return Size.Value;

            // Clear out any existing children and pseudo-invalidate the panel
            generatedPanel = ItemsPanelTemplate == null ? new StackPanel() : ItemsPanelTemplate.GenerateItem(DataContext) as Panel;

			generatedPanel.Parent = this;

            if (ItemsSource == null || ItemsSource.OfType<object>().Count() == 0)
            {
                // If there are no items, then go ahead and return zero
                Size = Vector2.zero;
                return Vector2.zero;
            }

            // Now let's add back in any children items we need
            foreach (var item in ItemsSource)
                generatedPanel.AddChild(ItemTemplate.GenerateItem(item));

            // Now let's measure the size of the panel
            var size = generatedPanel.Measure();

            Size = size;

            return size;
        }
Beispiel #2
0
        public Menu()
        {
            menuItems = new List<MenuItem>();

            itemPanel = new StackPanel();

            var border = new Border();
            border.Padding = new Thickness(10);

            border.AddChild(itemPanel);

            Child = border;

            selectedIndex = -1;
        }
Beispiel #3
0
		private static void LoadPanel(Panel panel, XmlNode panelXml, object viewModel)
		{
			var currentAssembly = loadedTypes.Keys.FirstOrDefault();

			foreach (var childNode in panelXml.ChildNodes.OfType<XmlNode>())
			{
				Type childType = null;

				if (string.IsNullOrEmpty(childNode.NamespaceURI))
					childType = loadedTypes[currentAssembly].FirstOrDefault(t => t.Name == childNode.LocalName);
				else
				{
					var typeName = string.Format("{0}.{1}", childNode.NamespaceURI, childNode.LocalName);

					// I think we get away with this for right now, because importing UPF into your project doesn't
					// produce multiple dlls, you still just get the Assembly-CSharp.dll
					var assembly = Assembly.GetExecutingAssembly();

					childType = loadedTypes[assembly].FirstOrDefault(t => t.FullName == typeName);
				}

				if (childType != null)
				{
					var child = Activator.CreateInstance(childType);
					panel.AddChild(child as Control);

					// Load attributes first, in case this is a panel
					LoadAttributes(child as Control, childNode, viewModel);

					if (child is Panel)
						LoadPanel(child as Panel, childNode, viewModel);
				}
				else
					Debug.LogError("Could not locate class for type: " + childNode.LocalName);
			}
		}
Beispiel #4
0
		internal override void InvalidateLayout(Control source)
		{
			generatedPanel = null;

			base.InvalidateLayout(source);
		}
Beispiel #5
0
 public void AddPanel(Panel panel)
 {
     panels.Add(panel);
 }