本文整理汇总了C#中ElementCollection.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ElementCollection.Add方法的具体用法?C# ElementCollection.Add怎么用?C# ElementCollection.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ElementCollection
的用法示例。
在下文中一共展示了ElementCollection.Add方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateHierarchy
public ElementCollection CreateHierarchy()
{
ElementCollection result = new ElementCollection();
for (int index = 0; index < elements.Count; index++)
{
Element element = elements[index];
if (element is Entity.Text)
result.Add(element);
else if (element is Expression)
result.Add(element);
else if (element is Tag)
{
result.Add(CollectForTag((Tag) element, ref index));
}
else if (element is TagClose)
{
throw new ParseException("Close tag for " + ((TagClose) element).Name + " doesn't have matching start tag.", element.Line, element.Col);
}
else
throw new ParseException("Invalid element: " + element.GetType().ToString(), element.Line, element.Col);
}
return result;
}
示例2: RaisesCollectionChangedEvent
public void RaisesCollectionChangedEvent()
{
var collection = new ElementCollection<Axis>(new PlotModel());
ElementCollectionChangedEventArgs<Axis> eventArgs = null;
var raisedCount = 0;
collection.CollectionChanged += (sender, e) =>
{
eventArgs = e;
raisedCount++;
};
var axis = new LinearAxis();
collection.Add(axis);
Assert.AreEqual(1, raisedCount);
Assert.AreEqual(1, eventArgs.AddedItems.Count);
Assert.IsTrue(ReferenceEquals(axis, eventArgs.AddedItems[0]));
}
示例3: GetChildTagsByTagName
/// <summary>
/// 根据标签名获取所有同标签名的子元素标签
/// </summary>
/// <param name="tagName"></param>
/// <returns></returns>
public virtual ElementCollection<Tag> GetChildTagsByTagName(string tagName)
{
if (string.IsNullOrEmpty(tagName)) throw new ArgumentNullException("tagName");
ElementCollection<Tag> tags = new ElementCollection<Tag>();
//搜索当前元素下的子元素
foreach (Element item in this.InnerElements)
{
if (item is Tag)
{
Tag tag = (Tag)item;
if (tagName.Equals(tag.TagName, StringComparison.InvariantCultureIgnoreCase)) tags.Add(tag);
//处理其下子元素
tags.AddRange(tag.GetChildTagsByTagName(tagName));
}
}
return tags;
}
示例4: GetChildTemplatesByName
/// <summary>
/// 获取所有具有同名称的模板列表.
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public ElementCollection<Template> GetChildTemplatesByName(string name)
{
if (string.IsNullOrEmpty(name)) throw new ArgumentNullException("name");
ElementCollection<Template> items = new ElementCollection<Template>();
foreach (Template template in TagContainer.ChildTemplates)
{
if (name.Equals(template.Name, StringComparison.InvariantCultureIgnoreCase))
{
items.Add(template);
}
items.AddRange(template.GetChildTemplatesByName(name));
}
return items;
}
示例5: CloneOverride
protected override void CloneOverride ([NotNull] BindableObject obj)
{
var source = (Element)obj;
base.CloneOverride(source);
if (HasChildren) {
_children = new ElementCollection(source);
foreach (Element child in source._children) {
var childClone = (Element)child.Clone();
childClone.DataContext = null;
_children.Add(childClone);
}
}
}