本文整理汇总了C#中System.Windows.Controls.ContentControl.ApplyTemplate方法的典型用法代码示例。如果您正苦于以下问题:C# ContentControl.ApplyTemplate方法的具体用法?C# ContentControl.ApplyTemplate怎么用?C# ContentControl.ApplyTemplate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.ContentControl
的用法示例。
在下文中一共展示了ContentControl.ApplyTemplate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateContextContainer
private void CreateContextContainer()
{
_container = new ContentControl();
_container.Template = _skimmingPanel.ContextContainerTemplate;
bool applied = _container.ApplyTemplate();
_contextPanel = _container.Template.FindName("PART_ContextPanel", _container) as Panel;
// For visual updates
AddVisualChild(_container);
}
示例2: VisualTreeTest3b
public void VisualTreeTest3b ()
{
// Check whether the grid + TextBlock is reused or replaced
Grid grid = null;
TextBlock textBlock = null;
ContentControl c = new ContentControl ();
// If there is no control template, a Grid + TextBlock is
// appended.
c.Content = "I'm a string";
Assert.IsTrue (c.ApplyTemplate (), "#1");
Assert.VisualChildren (c, "#2",
new VisualNode<Grid> ("#a", g => grid = g,
new VisualNode<TextBlock> ("#b", b => textBlock = b)
)
);
Assert.IsNull (textBlock.DataContext, "#3");
Assert.AreEqual ("", textBlock.Text, "#4");
// Changing the content to anther non-UIElement does not change
// the grid/textblock instance
c.Content = "Other string";
Assert.IsFalse (c.ApplyTemplate (), "#5");
Assert.VisualChildren (c, "#6",
new VisualNode<Grid> ("#a", g => Assert.AreSame (g, grid, "#b"),
new VisualNode<TextBlock> ("#c", b => Assert.AreSame (textBlock, b))
)
);
Assert.AreEqual ("", textBlock.Text, "#7");
}
示例3: VisualTreeTest3
public void VisualTreeTest3 ()
{
ContentControl c = new ContentControl ();
c.Content = "I'm a string";
Assert.VisualChildren (c, "#3"); // No visual children
Assert.IsTrue (c.ApplyTemplate (), "#4");
Assert.VisualChildren (c, "#5",
new VisualNode<Grid> ("#a",
new VisualNode<TextBlock> ("#b")
)
);
TextBlock block = null;
CreateAsyncTest (c,
() => {
Assert.VisualChildren (c, "#6",
new VisualNode<ContentPresenter> ("#c",
new VisualNode<Grid> ("#d",
new VisualNode<TextBlock> ("#e", (b) => block = b)
)
)
);
},
// This is probably a once off binding
() => Assert.IsInstanceOfType<BindingExpressionBase> (block.ReadLocalValue (TextBlock.TextProperty), "#6")
);
}
示例4: VisualTreeTest2
public void VisualTreeTest2 ()
{
ContentControl c = new ContentControl ();
Assert.VisualChildren (c, "#1");
Assert.IsFalse (c.ApplyTemplate (), "#2");
c.Content = new Rectangle ();
Assert.VisualChildren (c, "#3"); // No visual children
Assert.IsTrue (c.ApplyTemplate (), "#4");
Assert.VisualChildren (c, "#5",
new VisualNode<Rectangle> ("#a", (VisualNode [ ]) null)
);
CreateAsyncTest (c, () => {
Assert.VisualChildren (c, "#6",
new VisualNode<ContentPresenter> ("#b",
new VisualNode<Rectangle> ("#c")
)
);
});
}
示例5: NewTemplateDoesNotApplyInstantly
public void NewTemplateDoesNotApplyInstantly ()
{
ContentControl c = new ContentControl ();
c.Content = "Test";
CreateAsyncTest (c,
() => c.ApplyTemplate (),
() => {
// Start off with the default template
Assert.VisualChildren (c, "#1",
new VisualNode<ContentPresenter> ("#a", (VisualNode []) null)
);
// Changing the template does not make it apply instantly.
// It just clears the children.
c.Template = CreateTemplate ("<Canvas />");
Assert.VisualChildren (c, "#2");
}, () => {
Assert.VisualChildren (c, "#3",
new VisualNode<Canvas> ("#c")
);
}
);
}
示例6: InvalidTemplateObjectChild
public void InvalidTemplateObjectChild ()
{
// ContentTemplate is ignored if there is a Template
ContentControl c = new ContentControl {
Content = "Test",
Template = CreateTemplate ("<Storyboard />"),
};
CreateAsyncTest (c,
() => c.ApplyTemplate (),
() => {
// Start off with the default template
Assert.VisualChildren (c, "#1",
new VisualNode<Grid> ("#a",
new VisualNode<TextBlock> ("#b")
)
);
}
);
}
示例7: IsEnabledTest3
public void IsEnabledTest3 ()
{
ContentControl a = new ContentControl ();
ContentControl b = new ContentControl ();
a.Content = b;
a.IsEnabled = false;
Assert.IsTrue (b.IsEnabled, "#1");
a.ApplyTemplate ();
Assert.IsTrue (b.IsEnabled, "#2");
a.Measure (new Size { Height = 10, Width = 10 });
Assert.IsTrue (b.IsEnabled, "#3");
CreateAsyncTest (a,
() => Assert.IsFalse (b.IsEnabled, "#4")
);
}
示例8: DontCreateDynamicTransitionsOnAnimatedProperties
public void DontCreateDynamicTransitionsOnAnimatedProperties ()
{
var c = new ContentControl { Template = GetTemplate_MultipleTransitions () };
TestPanel.Children.Add (c);
c.ApplyTemplate ();
Assert.IsTrue (VisualStateManager.GoToState (c, "A", true), "#1");
Assert.IsTrue (VisualStateManager.GoToState (c, "B", true), "#2");
}
示例9: ContentTemplateNotUsed3
public void ContentTemplateNotUsed3 ()
{
ContentControl c = new ContentControl {
Content = new Button { Content = "Hello World" },
ContentTemplate = CreateDataTemplate ("<ContentControl />"),
Template = null
};
CreateAsyncTest (c,
() => c.ApplyTemplate (),
() => {
// Start off with the default template
Assert.VisualChildren (c, "#1",
new VisualNode<Button> ("#a", (VisualNode []) null)
);
}
);
}
示例10: ContentTemplateNotUsed2
public void ContentTemplateNotUsed2 ()
{
ContentControl c = new ContentControl {
Content = "Test",
ContentTemplate = CreateDataTemplate ("<ContentControl />"),
Template = null
};
CreateAsyncTest (c,
() => c.ApplyTemplate (),
() => {
// Start off with the default template
Assert.VisualChildren (c, "#1",
new VisualNode<Grid> ("#a",
new VisualNode <TextBlock> ("#b")
)
);
}
);
}
示例11: ContentTemplateNotUsed
public void ContentTemplateNotUsed ()
{
ContentControl c = new ContentControl ();
c.Content = "Test";
c.ContentTemplate = CreateDataTemplate ("<ContentControl />");
CreateAsyncTest (c,
() => c.ApplyTemplate (),
() => {
// Start off with the default template
Assert.VisualChildren (c, "#1",
new VisualNode<ContentPresenter> ("#a", (VisualNode []) null)
);
}
);
}
示例12: ContentIsRoot
public void ContentIsRoot ()
{
var c = new ContentControl { Content = new Rectangle () };
Assert.IsTrue (c.ApplyTemplate (), "#1");
Assert.AreEqual (1, VisualTreeHelper.GetChildrenCount (c), "#2");
Assert.AreSame (c.Content, VisualTreeHelper.GetChild (c, 0), "#3");
}
示例13: TransitionPropertyMismatchesStateProperty
public void TransitionPropertyMismatchesStateProperty ()
{
var c = new ContentControl { Template = GetTemplate_MismatchedTargetProperties () };
TestPanel.Children.Add (c);
c.ApplyTemplate ();
Assert.IsTrue (VisualStateManager.GoToState (c, "A", true), "#1");
Assert.IsTrue (VisualStateManager.GoToState (c, "B", true), "#2");
Assert.IsTrue (VisualStateManager.GoToState (c, "A", true), "#3");
}
示例14: OnContentChanged
protected virtual void OnContentChanged(object oldContent, object newContent)
{
if (this.grid == null)
{
this.ApplyTemplate();
}
ContentControl oldWrapper = this.currentWrappedContent;
if (oldWrapper != null)
{
VisualStateGroup layoutStatesGroup = FindNameInWrapper(oldWrapper, "LayoutStates") as VisualStateGroup;
if (layoutStatesGroup == null)
{
this.grid.Children.Remove(oldWrapper);
SetContent(oldWrapper, null);
}
else
{
layoutStatesGroup.CurrentStateChanged += delegate(object sender, VisualStateChangedEventArgs args)
{
this.grid.Children.Remove(oldWrapper);
SetContent(oldWrapper, null);
};
VisualStateManager.GoToState(oldWrapper, this.Reversed ? "BeforeLoaded" : "BeforeUnloaded", true);
}
}
ContentControl newWrapper = new ContentControl();
newWrapper.Style = this.TransitionStyle;
newWrapper.HorizontalContentAlignment = HorizontalAlignment.Stretch;
newWrapper.VerticalContentAlignment = VerticalAlignment.Stretch;
this.grid.Children.Add(newWrapper);
newWrapper.ApplyTemplate();
if (this.TransitionStyle != null)
{
SetContent(newWrapper, newContent);
if (oldWrapper != null)
{
VisualStateManager.GoToState(newWrapper, this.Reversed ? "BeforeUnloaded" : "BeforeLoaded", false);
VisualStateManager.GoToState(newWrapper, "AfterLoaded", true);
}
}
this.currentWrappedContent = newWrapper;
}
示例15: DataTemplateTest2
public void DataTemplateTest2 ()
{
// Fails in Silverlight 3
ContentControl c = new ContentControl ();
c.Content = new ConcreteFrameworkElement ();
c.ContentTemplate = new DataTemplate ();
CreateAsyncTest (c,
() => c.ApplyTemplate (),
() =>
Assert.VisualChildren (c, "#1",
new VisualNode<ContentPresenter> ("#1a")
)
);
}