/// <summary> /// 添加新目录。 /// </summary> /// <param name="selectedItem">选中的目录。</param> /// <param name="toAdd">要添加的目录。</param> private void AddElement(Core.Element selectedItem, Core.Element toAdd) { if (selectedItem is Core.Container c) { c.Add(toAdd); } }
private static bool TryGetElementType(Core.Element template, Dictionary <string, Attribute> attributes, Type elementBaseType, out Type type, out string className) { if (attributes.TryGetValue("x:Class", out var xClass)) { className = xClass.Value; } else if (!string.IsNullOrWhiteSpace(template.className)) { className = template.className; } else { className = elementBaseType.FullName; } if (!string.IsNullOrWhiteSpace(xClass.Value)) { if (TryGetType(xClass.Value, out var xClassType)) { type = xClassType; return(true); } else { // xClass hasn't been generated yet } } if (!string.IsNullOrWhiteSpace(template.className)) { if (TryGetType(template.className, out var templateType)) { type = templateType; return(true); } else { // Type should exist if specified in schema type = null; return(false); } } type = elementBaseType; return(true); }
private Data.Element ParseElement(Core.Element template, Data.Element parent) { var attributes = ReadAttributes(reader); if (!TryGetElementType(template, attributes, elementBaseType, out var ownerType, out var className)) { throw new Exception($"Failed to get type {className}"); } var typeInfo = ElementRegistry.GetElementType(ownerType); var namespaces = attributes .Where(p => NamespaceAttribute.IsNamespaceKey(p.Value) && NamespaceAttribute.IsCLRNamespace(p.Value)) .Select(p => NamespaceAttribute.Parse(p.Value).Value) .ToList(); if (parent == null && schema.namespaces != null) { namespaces.Add(schema.namespaces); } var nsHierarchy = GetElementChain(parent) .SelectMany(e => e.namespaces) .Concat(namespaces); var properties = attributes .Where(p => typeInfo.hierarchyProps.ContainsKey(p.Key, nsHierarchy)) .ToDictionary(p => p.Key, p => p.Value); var events = attributes .Where(p => EventManager.HasRoutedEvent(p.Key, ownerType, nsHierarchy)) .ToDictionary(p => p.Key, p => p.Value); return(new Data.Element { parent = parent, name = reader.Name, className = className, type = ownerType, rawAttributes = attributes, properties = properties, events = events, namespaces = namespaces }); }
private void CollectionListener_DeepCollectionChanged(object sender, DeepCollectionChangedEventArg e) { if (e.PropertyName == this.ItemsSourceSelector) { if (e.RemoveItems != null) { foreach (var remove in e.RemoveItems) { this.Children.Remove(this.Children.First(ie => ((HierarchicalNode)ie).Item == remove)); } } if (e.AddedItems != null) { HierarchicalNode parentCtrl = (HierarchicalNode)this.Children.FirstOrDefault(ie => ((HierarchicalNode)ie).Item == sender); int level = 0; if (parentCtrl != null) { level = parentCtrl.Level + 1; } foreach (var add in e.AddedItems) { Core.Element template = null; if (this.ItemTemplate != null) { template = (Core.Element) this.ItemTemplate.CreateContent(); } var ctrl = new HierarchicalNode(add, level, template); if (parentCtrl != null) { parentCtrl.ChildrenNode.Add(ctrl); } Children.Add(ctrl); } } } }
private void GetElementFromPoint(object state) { if (this.isBusy) { return; } this.isBusy = true; this.hasPending = false; try { var e = this.pointEvent; Console.Clear(); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("GET_QUERY_FROM_ELEMENT_FROM_POINT {0} {1}", e.X, e.Y); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine(); Context context = this.contexts.First(); Core.Element element = context.GetElementFromPoint(e.X, e.Y); this.highligter.Invoke(element.Bounds, Color.Red); foreach (var ctx in this.contexts.Skip(1)) { if (ctx.GetElementFromPoint(e.X, e.Y) is Core.Element elem) { context = ctx; element = elem; continue; } } var query = element.GetQuery(); Console.WriteLine(query); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Press the CTRL key to get the elements using the query."); Console.WriteLine(); if (e.Type == InputEventType.KeyUp) { this.Result = query; } } catch (Exception ex) { Console.WriteLine("ERROR: {0}", ex); } finally { this.isBusy = false; if (this.hasPending) { this.pointTimer.Change(0, Timeout.Infinite); } } }