コード例 #1
0
        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");
        }
コード例 #2
0
        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");
        }
コード例 #3
0
 public static void RefreshResources()
 {
     foreach (var dictionary in TimelineResourceSets)
     {
         var list = new List <KeyValuePair <object, SolidColorBrush> >();
         foreach (var key in dictionary.Keys)
         {
             var sb = dictionary[key] as SolidColorBrush;
             if (sb == null)
             {
                 continue;
             }
             var r   = (string)sb.GetValue(ResourceSourceNameProperty);
             var nsb = new SolidColorBrush();
             nsb.SetValue(ResourceSourceNameProperty, r);
             nsb.SetValue(SolidColorBrush.ColorProperty, Application.Current.FindResource(r));
             list.Add(new KeyValuePair <object, SolidColorBrush>(key, nsb));
         }
         list.ForEach(p => dictionary[p.Key] = p.Value);
     }
 }
コード例 #4
0
        public void BrushWithOneParent_Null()
        {
            var brush = new SolidColorBrush();

            brush.SetValue(FrameworkElement.NameProperty, "Test");

            var first = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");

            first.Foreground = brush;

            first.Foreground = null;
            Assert.IsNull(first.FindName("Test"), "#1");
        }
コード例 #5
0
        public void BrushWithTwoParents_SecondCannotFindName()
        {
            // 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;

            Assert.AreSame(brush, first.FindName("Test"), "#1");
            Assert.IsNull(second.FindName("Test"), "#2");
        }
コード例 #6
0
        public static SolidColorBrush SetIdentity(
            [NotNull] this SolidColorBrush @this,
            [CanBeNull] MaterialIdentity materialIdentity)
        {
            @this.IsNotNull(nameof(@this));

            if ((@this.CanFreeze && @this.IsFrozen) || @this.IsSealed)
            {
                //@this.Changed += (s, args) =>
                //{

                //};
                var cloned = @this.Clone();

                cloned.SetValue(
                    MDH.IdentityProperty,
                    materialIdentity);

                cloned.Freeze();

                return(cloned);
            }
            else
            {
                //@this.Changed += (s, args) =>
                //{

                //};

                var existingIdentity = @this.GetIdentity();
                if (existingIdentity != null)
                {
                    if (!existingIdentity.Equals(materialIdentity))
                    {
                    }
                }
                @this.SetValue(
                    MDH.IdentityProperty,
                    materialIdentity);

                if (@this.CanFreeze)
                {
                    @this.Freeze();
                }

                return(@this);
            }
        }
コード例 #7
0
        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");
        }
コード例 #8
0
        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");
        }
コード例 #9
0
        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");
        }
コード例 #10
0
        public void BrushWithThreeParents_NullInParentOrder()
        {
            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;

            first.Foreground  = null;
            second.Foreground = null;
            third.Foreground  = null;

            Assert.AreSame(brush, first.FindName("Test"), "#1");
            Assert.IsNull(second.FindName("Test"), "#1");
            Assert.IsNull(third.FindName("Test"), "#1");
        }
コード例 #11
0
        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");
        }
コード例 #12
0
        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");
        }
コード例 #13
0
 internal static void SetColorKey(SolidColorBrush element, object value)
 {
     element.SetValue(ColorKeyProperty, value);
 }
コード例 #14
0
        private static IEnumerable <ResourceDictionary> CreateResources()
        {
            var keys = new[]
            {
                "TweetBackgroundBrush",
                "TweetForegroundBrush",
                "TweetHighlightBackgroundBrush",
                "TweetHighlightForegroundBrush",
                "KeyTextBrush",
                "SubTextBrush",
                "HyperlinkTextBrush",
                "FavoriteCounter",
                "RetweetCounter",
                "RetweetMarker",
                "FavAndRtBackground",
                "FavAndRtForeground",
                "FavAndRtHoveringBackground",
                "FavAndRtHoveringForeground",
                "FavAndRtPressedBackground",
                "FavAndRtPressedForeground",
                "FavoriteBackground",
                "FavoriteForeground",
                "FavoriteHoveringBackground",
                "FavoriteHoveringForeground",
                "FavoritePressedBackground",
                "FavoritePressedForeground",
                "ColoredFavoriteBackground",
                "ColoredFavoriteForeground",
                "ColoredFavoriteHoveringBackground",
                "ColoredFavoriteHoveringForeground",
                "ColoredFavoritePressedBackground",
                "ColoredFavoritePressedForeground",
                "RetweetBackground",
                "RetweetForeground",
                "RetweetHoveringBackground",
                "RetweetHoveringForeground",
                "RetweetPressedBackground",
                "RetweetPressedForeground",
                "ColoredRetweetBackground",
                "ColoredRetweetForeground",
                "ColoredRetweetHoveringBackground",
                "ColoredRetweetHoveringForeground",
                "ColoredRetweetPressedBackground",
                "ColoredRetweetPressedForeground",
                "MentionBackground",
                "MentionForeground",
                "MentionHoveringBackground",
                "MentionHoveringForeground",
                "MentionPressedBackground",
                "MentionPressedForeground",
                "DeleteBackground",
                "DeleteForeground",
                "DeleteHoveringBackground",
                "DeleteHoveringForeground",
                "DeletePressedBackground",
                "DeletePressedForeground"
            };
            var resourceChannels = new[]
            {
                "Default",
                "Myself",
                "Mention",
                "Retweet",
                "Message"
            };
            var resources = new[]
            {
                "Tweet{0}Background",
                "Tweet{0}Foreground",
                "Tweet{0}HighlightBackground",
                "Tweet{0}HighlightForeground",
                "Tweet{0}KeyText",
                "Tweet{0}SubText",
                "Tweet{0}HyperlinkText",
                "Tweet{0}FavoriteCounter",
                "Tweet{0}RetweetCounter",
                "Tweet{0}RetweetMarker",
                "Tweet{0}FavAndRtButtonBackground",
                "Tweet{0}FavAndRtButtonForeground",
                "Tweet{0}FavAndRtButtonHoveringBackground",
                "Tweet{0}FavAndRtButtonHoveringForeground",
                "Tweet{0}FavAndRtButtonPressedBackground",
                "Tweet{0}FavAndRtButtonPressedForeground",
                "Tweet{0}FavoriteButtonBackground",
                "Tweet{0}FavoriteButtonForeground",
                "Tweet{0}FavoriteButtonHoveringBackground",
                "Tweet{0}FavoriteButtonHoveringForeground",
                "Tweet{0}FavoriteButtonPressedBackground",
                "Tweet{0}FavoriteButtonPressedForeground",
                "Tweet{0}ColoredFavoriteButtonBackground",
                "Tweet{0}ColoredFavoriteButtonForeground",
                "Tweet{0}ColoredFavoriteButtonHoveringBackground",
                "Tweet{0}ColoredFavoriteButtonHoveringForeground",
                "Tweet{0}ColoredFavoriteButtonPressedBackground",
                "Tweet{0}ColoredFavoriteButtonPressedForeground",
                "Tweet{0}RetweetButtonBackground",
                "Tweet{0}RetweetButtonForeground",
                "Tweet{0}RetweetButtonHoveringBackground",
                "Tweet{0}RetweetButtonHoveringForeground",
                "Tweet{0}RetweetButtonPressedBackground",
                "Tweet{0}RetweetButtonPressedForeground",
                "Tweet{0}ColoredRetweetButtonBackground",
                "Tweet{0}ColoredRetweetButtonForeground",
                "Tweet{0}ColoredRetweetButtonHoveringBackground",
                "Tweet{0}ColoredRetweetButtonHoveringForeground",
                "Tweet{0}ColoredRetweetButtonPressedBackground",
                "Tweet{0}ColoredRetweetButtonPressedForeground",
                "Tweet{0}MentionButtonBackground",
                "Tweet{0}MentionButtonForeground",
                "Tweet{0}MentionButtonHoveringBackground",
                "Tweet{0}MentionButtonHoveringForeground",
                "Tweet{0}MentionButtonPressedBackground",
                "Tweet{0}MentionButtonPressedForeground",
                "Tweet{0}DeleteButtonBackground",
                "Tweet{0}DeleteButtonForeground",
                "Tweet{0}DeleteButtonHoveringBackground",
                "Tweet{0}DeleteButtonHoveringForeground",
                "Tweet{0}DeleteButtonPressedBackground",
                "Tweet{0}DeleteButtonPressedForeground"
            };

            for (int i = 0; i < resourceChannels.Length; i++)
            {
                var nrd  = new ResourceDictionary();
                var cmod = resourceChannels[i];
                resources
                .Select(s => String.Format(s, cmod))
                .Zip(keys, (r, k) =>
                {
                    var sb = new SolidColorBrush();
                    sb.SetValue(ResourceSourceNameProperty, r);
                    sb.SetValue(SolidColorBrush.ColorProperty, Application.Current.FindResource(r));
                    return(new { Key = k, Resource = sb });
                })
                .ForEach(b => nrd.Add(b.Key, b.Resource));
                yield return(nrd);
            }
        }