本文整理汇总了C#中System.Windows.FrameworkElement.AddVisualChild方法的典型用法代码示例。如果您正苦于以下问题:C# FrameworkElement.AddVisualChild方法的具体用法?C# FrameworkElement.AddVisualChild怎么用?C# FrameworkElement.AddVisualChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.FrameworkElement
的用法示例。
在下文中一共展示了FrameworkElement.AddVisualChild方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResourceReferenceExpressionBaseTest
public void ResourceReferenceExpressionBaseTest()
{
FrameworkElement root = new FrameworkElement();
FrameworkElement child1 = new FrameworkElement();
FrameworkElement child2 = new FrameworkElement();
child1.AddVisualChild(child2);
int testValueChanged = 0;
child2.PropertyChanged += (sender, e) => testValueChanged += e.Property == TestValueProperty ? 1 : 0;
child2.SetValue(TestValueProperty, new ResourceReferenceExpressionProvider("key1"));
Assert.AreEqual("default", child2.GetValue(TestValueProperty));
Assert.AreEqual(0, testValueChanged);
root.Resources = new ResourceDictionary();
root.Resources.Add("key1", "value1");
root.AddVisualChild(child1);
Assert.AreEqual("value1", child2.GetValue(TestValueProperty));
Assert.AreEqual(1, testValueChanged);
root.Resources.Remove("key1");
Assert.AreEqual("default", child2.GetValue(TestValueProperty));
Assert.AreEqual(2, testValueChanged);
ResourceDictionary dictionary = new ResourceDictionary();
dictionary.Add("key1", "value2");
root.Resources.MergedDictionaries.Add(dictionary);
Assert.AreEqual("value2", child2.GetValue(TestValueProperty));
Assert.AreEqual(3, testValueChanged);
child1.Resources = new ResourceDictionary();
child1.Resources.Add("key1", "value3");
Assert.AreEqual("value3", child2.GetValue(TestValueProperty));
Assert.AreEqual(4, testValueChanged);
child1.Resources.Remove("key1");
Assert.AreEqual("value2", child2.GetValue(TestValueProperty));
Assert.AreEqual(5, testValueChanged);
}
示例2: ResourceInheritanceTest
public void ResourceInheritanceTest()
{
object value;
FrameworkElement root = new FrameworkElement();
root.Resources = new ResourceDictionary();
root.Resources.Add("key1", "value1");
Assert.IsTrue(root.TryGetResource("key1", out value));
Assert.AreEqual("value1", value);
FrameworkElement child1 = new FrameworkElement();
root.AddVisualChild(child1);
root.AddLogicalChild(child1);
Assert.IsTrue(child1.TryGetResource("key1", out value));
Assert.AreEqual("value1", value);
child1.Resources = new ResourceDictionary();
child1.Resources.Add("key1", "value2");
FrameworkElement child2 = new FrameworkElement();
child1.AddVisualChild(child2);
Assert.IsTrue(child2.TryGetResource("key1", out value));
Assert.AreEqual("value2", value);
root.AddLogicalChild(child2);
Assert.IsTrue(child2.TryGetResource("key1", out value));
Assert.AreEqual("value1", value);
}