本文整理汇总了C#中System.Windows.Controls.Control.GetBaseValueSource方法的典型用法代码示例。如果您正苦于以下问题:C# Control.GetBaseValueSource方法的具体用法?C# Control.GetBaseValueSource怎么用?C# Control.GetBaseValueSource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.Control
的用法示例。
在下文中一共展示了Control.GetBaseValueSource方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TemplateApplyTest
public void TemplateApplyTest()
{
string text = @"
<ControlTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' x:Name='root'>
<FrameworkElement x:Name='child' Height='400'/>
<ControlTemplate.Triggers>
<Trigger Property='FrameworkElement.Width' Value='100'>
<Setter Property='FrameworkElement.Height' Value='100'/>
</Trigger>
<Trigger Property='FrameworkElement.Width' Value='200'>
<Setter Property='FrameworkElement.Height' Value='200'/>
<Setter TargetName='child' Property='FrameworkElement.Height' Value='200'/>
</Trigger>
<EventTrigger RoutedEvent='FrameworkElement.Initialized'>
<Setter Property='FrameworkElement.Height' Value='300'/>
</EventTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>";
ControlTemplate controlTemplate = XamlLoader.Load(XamlParser.Parse(text)) as ControlTemplate;
Control control = new Control();
control.Width = 100;
control.Template = controlTemplate;
control.ApplyTemplate();
Assert.AreEqual(1, control.VisualChildren.Count());
FrameworkElement child1 = control.TemplateChild as FrameworkElement;
Assert.IsNotNull(child1);
FrameworkElement child2 = control.Template.FindName("child", control) as FrameworkElement;
Assert.AreEqual(child1, child2);
Assert.AreEqual(control, child1.TemplatedParent);
Assert.AreEqual(400, child1.Height);
Assert.AreEqual(BaseValueSource.ParentTemplate, child1.GetValueSource(FrameworkElement.HeightProperty).BaseValueSource);
Assert.AreEqual(BaseValueSource.ParentTemplate, child1.GetBaseValueSource(FrameworkElement.HeightProperty));
Assert.AreEqual(100, control.Height);
Assert.AreEqual(BaseValueSource.TemplateTrigger, control.GetValueSource(FrameworkElement.HeightProperty).BaseValueSource);
Assert.AreEqual(BaseValueSource.TemplateTrigger, control.GetBaseValueSource(FrameworkElement.HeightProperty));
control.Width = 200;
Assert.AreEqual(200, control.Height);
Assert.AreEqual(BaseValueSource.TemplateTrigger, control.GetValueSource(FrameworkElement.HeightProperty).BaseValueSource);
Assert.AreEqual(BaseValueSource.TemplateTrigger, control.GetBaseValueSource(FrameworkElement.HeightProperty));
Assert.AreEqual(200, child1.Height);
Assert.AreEqual(BaseValueSource.ParentTemplateTrigger, child1.GetValueSource(FrameworkElement.HeightProperty).BaseValueSource);
Assert.AreEqual(BaseValueSource.ParentTemplateTrigger, child1.GetBaseValueSource(FrameworkElement.HeightProperty));
control.RaiseEvent(new RoutedEventArgs(FrameworkElement.InitializedEvent, control));
Assert.AreEqual(300, control.Height);
Assert.AreEqual(BaseValueSource.TemplateTrigger, control.GetValueSource(FrameworkElement.HeightProperty).BaseValueSource);
Assert.AreEqual(BaseValueSource.TemplateTrigger, control.GetBaseValueSource(FrameworkElement.HeightProperty));
control.Template = null;
control.ApplyTemplate();
Assert.AreEqual(Double.NaN, control.Height);
}