本文整理汇总了C#中ItemsControl.ApplyTemplate方法的典型用法代码示例。如果您正苦于以下问题:C# ItemsControl.ApplyTemplate方法的具体用法?C# ItemsControl.ApplyTemplate怎么用?C# ItemsControl.ApplyTemplate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ItemsControl
的用法示例。
在下文中一共展示了ItemsControl.ApplyTemplate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Panel_Should_Have_TemplatedParent_Set_To_ItemsControl
public void Panel_Should_Have_TemplatedParent_Set_To_ItemsControl()
{
var target = new ItemsControl();
target.Template = GetTemplate();
target.Items = new[] { "Foo" };
target.ApplyTemplate();
Assert.Equal(target, target.Presenter.Panel.TemplatedParent);
}
示例2: Adding_Control_Item_Should_Make_Control_Appear_In_LogicalChildren
public void Adding_Control_Item_Should_Make_Control_Appear_In_LogicalChildren()
{
var target = new ItemsControl();
var child = new Control();
target.Template = GetTemplate();
target.Items = new[] { child };
target.ApplyTemplate();
Assert.Equal(new[] { child }, ((ILogical)target).LogicalChildren.ToList());
}
示例3: Item_Should_Have_TemplatedParent_Set_To_Null
public void Item_Should_Have_TemplatedParent_Set_To_Null()
{
var target = new ItemsControl();
target.Template = GetTemplate();
target.Items = new[] { "Foo" };
target.ApplyTemplate();
var item = (TextBlock)target.Presenter.Panel.GetVisualChildren().First();
Assert.Null(item.TemplatedParent);
}
示例4: Control_Item_Should_Have_Parent_Set
public void Control_Item_Should_Have_Parent_Set()
{
var target = new ItemsControl();
var child = new Control();
target.Template = GetTemplate();
target.Items = new[] { child };
target.ApplyTemplate();
Assert.Equal(target, child.Parent);
Assert.Equal(target, ((ILogical)child).LogicalParent);
}
示例5: Panel_Should_Have_TemplatedParent_Set_To_ItemsControl
public void Panel_Should_Have_TemplatedParent_Set_To_ItemsControl()
{
var target = new ItemsControl();
target.Template = GetTemplate();
target.Items = new[] { "Foo" };
target.ApplyTemplate();
var presenter = target.GetTemplateChildren().OfType<ItemsPresenter>().Single();
var panel = target.GetTemplateChildren().OfType<StackPanel>().Single();
Assert.Equal(target, panel.TemplatedParent);
}
示例6: Clearing_Control_Item_Should_Clear_Child_Controls_Parent
public void Clearing_Control_Item_Should_Clear_Child_Controls_Parent()
{
var target = new ItemsControl();
var child = new Control();
target.Template = GetTemplate();
target.Items = new[] { child };
target.ApplyTemplate();
target.Items = null;
Assert.Null(child.Parent);
Assert.Null(((ILogical)child).LogicalParent);
}
示例7: Container_Should_Have_TemplatedParent_Set_To_Null
public void Container_Should_Have_TemplatedParent_Set_To_Null()
{
var target = new ItemsControl();
target.Template = GetTemplate();
target.Items = new[] { "Foo" };
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
var container = (ContentPresenter)target.Presenter.Panel.Children[0];
Assert.Null(container.TemplatedParent);
}
示例8: Item_Should_Have_TemplatedParent_Set_To_Null
public void Item_Should_Have_TemplatedParent_Set_To_Null()
{
var target = new ItemsControl();
target.Template = GetTemplate();
target.Items = new[] { "Foo" };
target.ApplyTemplate();
var presenter = target.GetTemplateChildren().OfType<ItemsPresenter>().Single();
var panel = target.GetTemplateChildren().OfType<StackPanel>().Single();
var item = (TextBlock)panel.GetVisualChildren().First();
Assert.Null(item.TemplatedParent);
}
示例9: Adding_String_Item_Should_Make_TextBlock_Appear_In_LogicalChildren
public void Adding_String_Item_Should_Make_TextBlock_Appear_In_LogicalChildren()
{
var target = new ItemsControl();
var child = new Control();
target.Template = GetTemplate();
target.Items = new[] { "Foo" };
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
var logical = (ILogical)target;
Assert.Equal(1, logical.LogicalChildren.Count);
Assert.IsType<TextBlock>(logical.LogicalChildren[0]);
}
示例10: Adding_Control_Item_Should_Make_Control_Appear_In_LogicalChildren
public void Adding_Control_Item_Should_Make_Control_Appear_In_LogicalChildren()
{
var target = new ItemsControl();
var child = new Control();
target.Template = GetTemplate();
target.Items = new[] { child };
// Should appear both before and after applying template.
Assert.Equal(new ILogical[] { child }, target.GetLogicalChildren());
target.ApplyTemplate();
Assert.Equal(new ILogical[] { child }, target.GetLogicalChildren());
}
示例11: Should_Use_ItemTemplate_To_Create_Control
public void Should_Use_ItemTemplate_To_Create_Control()
{
var target = new ItemsControl
{
Template = GetTemplate(),
ItemTemplate = new FuncDataTemplate<string>(_ => new Canvas()),
};
target.Items = new[] { "Foo" };
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
var container = (ContentPresenter)target.Presenter.Panel.Children[0];
container.UpdateChild();
Assert.IsType<Canvas>(container.Child);
}
示例12: Nested_TemplatedControls_Should_Be_Expanded_And_Have_Correct_TemplatedParent
public void Nested_TemplatedControls_Should_Be_Expanded_And_Have_Correct_TemplatedParent()
{
var target = new ItemsControl
{
Template = new ControlTemplate<ItemsControl>(ItemsControlTemplate),
Items = new[] { "Foo", }
};
target.ApplyTemplate();
var scrollViewer = target.GetVisualDescendents()
.OfType<ScrollViewer>()
.Single();
var types = target.GetVisualDescendents()
.Select(x => x.GetType())
.ToList();
var templatedParents = target.GetVisualDescendents()
.OfType<IControl>()
.Select(x => x.TemplatedParent)
.ToList();
Assert.Equal(
new[]
{
typeof(Border),
typeof(ScrollViewer),
typeof(ScrollContentPresenter),
typeof(ItemsPresenter),
typeof(StackPanel),
typeof(TextBlock),
},
types);
Assert.Equal(
new object[]
{
target,
target,
scrollViewer,
target,
target,
null
},
templatedParents);
}
示例13: Adding_Items_Should_Fire_LogicalChildren_CollectionChanged
public void Adding_Items_Should_Fire_LogicalChildren_CollectionChanged()
{
var target = new ItemsControl();
var items = new PerspexList<string> { "Foo" };
var called = false;
target.Template = GetTemplate();
target.Items = items;
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
((ILogical)target).LogicalChildren.CollectionChanged += (s, e) =>
called = e.Action == NotifyCollectionChangedAction.Add;
items.Add("Bar");
Assert.True(called);
}
示例14: Container_Child_Should_Have_LogicalParent_Set_To_Container
public void Container_Child_Should_Have_LogicalParent_Set_To_Container()
{
using (UnitTestApplication.Start(TestServices.StyledWindow))
{
var root = new Window();
var target = new ItemsControl();
root.Content = target;
var templatedParent = new Button();
target.TemplatedParent = templatedParent;
target.Template = GetTemplate();
target.Items = new[] { "Foo" };
root.ApplyTemplate();
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
var container = (ContentPresenter)target.Presenter.Panel.Children[0];
Assert.Equal(container, container.Child.Parent);
}
}
示例15: DataTemplate_Created_Content_Should_Be_NameScope
public void DataTemplate_Created_Content_Should_Be_NameScope()
{
var items = new object[]
{
"foo",
};
var target = new ItemsControl
{
Template = GetTemplate(),
Items = items,
};
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
var container = (ContentPresenter)target.Presenter.Panel.LogicalChildren[0];
container.UpdateChild();
Assert.NotNull(NameScope.GetNameScope((TextBlock)container.Child));
}