本文整理汇总了C#中System.Windows.Media.SolidColorBrush.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# SolidColorBrush.SetValue方法的具体用法?C# SolidColorBrush.SetValue怎么用?C# SolidColorBrush.SetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.SolidColorBrush
的用法示例。
在下文中一共展示了SolidColorBrush.SetValue方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BrushWithTwoParents_TwoSubtrees_SetOneFirst
public void BrushWithTwoParents_TwoSubtrees_SetOneFirst()
{
var brush = new SolidColorBrush();
brush.SetValue(FrameworkElement.NameProperty, "Test");
var first = (Canvas)XamlReader.Load(@"<Canvas xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
var second = (Canvas)XamlReader.Load(@"<Canvas xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
first.Children.Add(new Canvas { Background = brush });
second.Children.Add(new Canvas { Background = brush });
Assert.AreSame(brush, first.FindName("Test"), "#1");
Assert.IsNull(second.FindName("Test"), "#2");
}
示例2: UseTwice
public void UseTwice()
{
string name = "SuperSecretBrush";
Brush b1 = new SolidColorBrush();
b1.SetValue(FrameworkElement.NameProperty, name);
var g1 = new Grid { Name = "g1", Background = b1 };
var g2 = new Grid { Name = "g2", Background = b1 };
TestPanel.Children.Add(g1);
Assert.IsNull(TestPanel.FindName(name), "#1");
TestPanel.Children.Add(g2);
Assert.IsNull(TestPanel.FindName(name), "#2");
}
示例3: UseTwice_ThenOnce
public void UseTwice_ThenOnce()
{
string name = "SuperSecretBrush";
Brush brush = new SolidColorBrush();
brush.SetValue(FrameworkElement.NameProperty, name);
var g1 = new Grid { Name = "g1", Background = brush };
var g2 = new Grid { Name = "g2", Background = brush };
TestPanel.Children.Add(g1);
Assert.IsNull(TestPanel.FindName(name), "#1");
g2.Background = null;
Assert.IsNull(TestPanel.FindName(name), "#2");
TestPanel.Children.Clear();
TestPanel.Children.Add(g1);
Assert.AreSame(brush, TestPanel.FindName(name), "#3");
}
示例4: BrushWithTwoParents_UnregisterWrongObject
public void BrushWithTwoParents_UnregisterWrongObject()
{
// Create two brushes with the same name. Put one of them in both
// textboxes and the other just in the second textbox. See if clearing
// the first brush in the second textbox will unregister the name of the
// second brush from the second textbox.
var brush = new SolidColorBrush();
brush.SetValue(FrameworkElement.NameProperty, "Test");
var secondBrush = new SolidColorBrush();
secondBrush.SetValue(FrameworkElement.NameProperty, "Test");
var first = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
var second = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
first.Foreground = brush;
second.Foreground = brush;
second.Background = secondBrush;
second.Foreground = null;
Assert.AreSame(secondBrush, second.FindName("Test"), "#1");
}
示例5: BrushWithThreeParents_ComplexParenting_AlternateNull
public void BrushWithThreeParents_ComplexParenting_AlternateNull()
{
var brush = new SolidColorBrush();
brush.SetValue(FrameworkElement.NameProperty, "Test");
var first = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
var second = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
var third = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
var fourth = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
first.Foreground = brush;
Assert.AreSame(brush, first.FindName("Test"), "#1a");
Assert.IsNull(second.FindName("Test"), "#2a");
Assert.IsNull(third.FindName("Test"), "#3a");
Assert.IsNull(fourth.FindName("Test"), "#4a");
second.Foreground = brush;
first.Foreground = null;
Assert.AreSame(brush, first.FindName("Test"), "#1b");
Assert.IsNull(second.FindName("Test"), "#2b");
Assert.IsNull(third.FindName("Test"), "#3b");
Assert.IsNull(fourth.FindName("Test"), "#4b");
third.Foreground = brush;
second.Foreground = null;
Assert.AreSame(brush, first.FindName("Test"), "#1c");
Assert.IsNull(second.FindName("Test"), "#2c");
Assert.IsNull(third.FindName("Test"), "#3c");
Assert.IsNull(fourth.FindName("Test"), "#4c");
fourth.Foreground = brush;
third.Foreground = null;
Assert.AreSame(brush, first.FindName("Test"), "#5a");
Assert.IsNull(second.FindName("Test"), "#5b");
Assert.IsNull(third.FindName("Test"), "#5c");
Assert.IsNull(fourth.FindName("Test"), "#5d");
fourth.Foreground = null;
Assert.AreSame(brush, first.FindName("Test"), "#6a");
Assert.IsNull(second.FindName("Test"), "#6b");
Assert.IsNull(third.FindName("Test"), "#6c");
Assert.IsNull(fourth.FindName("Test"), "#6d");
}
示例6: BrushWithThreeParents_NullInReverseOrder
public void BrushWithThreeParents_NullInReverseOrder()
{
var brush = new SolidColorBrush();
brush.SetValue(FrameworkElement.NameProperty, "Test");
var first = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
var second = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
var third = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
first.Foreground = brush;
second.Foreground = brush;
third.Foreground = brush;
third.Foreground = null;
second.Foreground = null;
first.Foreground = null;
Assert.IsNull(first.FindName("Test"), "#1");
Assert.IsNull(second.FindName("Test"), "#1");
Assert.IsNull(third.FindName("Test"), "#1");
}
示例7: BrushWithThreeParents_NullAll_ThenPutInNewNamescope
public void BrushWithThreeParents_NullAll_ThenPutInNewNamescope()
{
// Create two TextBlocks with unique namescopes and add the same brush to both.
// Then null the properties and add the brush to a third namescope to see if it
// is registered there.
var brush = new SolidColorBrush();
brush.SetValue(FrameworkElement.NameProperty, "Test");
var first = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
var second = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
var third = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
var fourth = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
first.Foreground = null;
second.Foreground = null;
third.Foreground = null;
fourth.Foreground = null;
first.Foreground = brush;
second.Foreground = brush;
third.Foreground = brush;
first.Foreground = null;
second.Foreground = null;
third.Foreground = null;
fourth.Foreground = brush;
Assert.AreSame(brush, fourth.FindName("Test"), "#1");
}
示例8: BrushWithTwoParents_NullBoth_NamescopeClash
public void BrushWithTwoParents_NullBoth_NamescopeClash()
{
// Create two TextBlocks with unique namescopes and add the same brush to both
// If we then clear the two Foregrounds by setting them to null, the name is never
// unregistered from the first namescope so if we try to reuse the name we blow up.
var first = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
var second = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
var brush = new SolidColorBrush();
brush.SetValue(FrameworkElement.NameProperty, "Test");
first.Foreground = brush;
second.Foreground = brush;
first.Foreground = null;
second.Foreground = null;
brush = new SolidColorBrush();
brush.SetValue(FrameworkElement.NameProperty, "Test");
Assert.Throws<ArgumentException>(() => first.Foreground = brush, "#1");
}
示例9: BrushWithTwoParents_NullBoth
public void BrushWithTwoParents_NullBoth()
{
// Create two TextBlocks with unique namescopes and add the same brush to both
// By setting the Foreground properties to null, the brush is still in the namescope
var first = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
var second = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
var brush = new SolidColorBrush();
brush.SetValue(FrameworkElement.NameProperty, "Test");
first.Foreground = brush;
second.Foreground = brush;
first.Foreground = null;
second.Foreground = null;
Assert.AreSame(brush, first.FindName("Test"), "#1");
Assert.IsNull(second.FindName("Test"), "#2");
}
示例10: BrushWithTwoParents_NullSecond_ThenPutInNewNamescope
public void BrushWithTwoParents_NullSecond_ThenPutInNewNamescope()
{
// Create two TextBlocks with unique namescopes and add the same brush to both
var first = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
var second = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
var brush = new SolidColorBrush();
brush.SetValue(FrameworkElement.NameProperty, "Test");
first.Foreground = brush;
second.Foreground = brush;
second.Foreground = null;
var third = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
third.Foreground = brush;
Assert.IsNull(third.FindName("Test"), "#1");
}