//  ===========================================================================
        //  These methods are invoked when a Style/Template cache needs to be updated
        //  ===========================================================================

        #region UpdateCache

        //
        //  This method
        //  1. Updates the style cache for the given fe/fce
        //
        internal static void UpdateStyleCache(
            FrameworkElement        fe,
            FrameworkContentElement fce,
            Style                   oldStyle,
            Style                   newStyle,
            ref Style               styleCache)
        {
            Debug.Assert(fe != null || fce != null);

            if (newStyle != null)
            {
                // We have a new style.  Make sure it's targeting the right
                // type, and then seal it.

                DependencyObject d = fe;
                if (d == null)
                {
                    d = fce;
                }
                newStyle.CheckTargetType(d);
                newStyle.Seal();
            }

            styleCache = newStyle;

            // Do style property invalidations. Note that some of the invalidations may be callouts
            // that could turn around and query the style property on this node. Hence it is essential
            // to update the style cache before we do this operation.
            StyleHelper.DoStyleInvalidations(fe, fce, oldStyle, newStyle);

            // Now look for triggers that might want their EnterActions or ExitActions
            //  to run immediately.
            StyleHelper.ExecuteOnApplyEnterExitActions(fe, fce, newStyle, StyleDataField);
        }
Example #2
0
 private void FontChanged(object sender, PrefChangeEventArgs e)
 {
     if (e.PrefName == "fiddler.ui.font.face")
     {
         var font = e.ValueString;
         var fontFamily = new FontFamily(font);
         _panel.Dispatcher.BeginInvoke((Action)(() =>
         {
             var style = new Style(typeof(StackPanel), _panel.Style);
             style.Setters.Add(new Setter(TextBlock.FontFamilyProperty, fontFamily));
             style.Seal();
             _panel.Style = style;
         }));
     }
     if (e.PrefName == "fiddler.ui.font.size")
     {
         double value;
         if (double.TryParse(e.ValueString, out value))
         {
             _panel.Dispatcher.BeginInvoke((Action) (() =>
             {
                 var fontSizeInPoints = value*96d/72d;
                 var style = new Style(typeof (StackPanel), _panel.Style);
                 style.Setters.Add(new Setter(TextBlock.FontSizeProperty, fontSizeInPoints));
                 style.Seal();
                 _panel.Style = style;
             }));
         }
     }
 }
 private Style CreateItemContainerStyle()
 {
     var style = new Style(typeof(MenuItem));
     style.Setters.Add(new Setter(MenuItem.CommandProperty,
         new Binding { Converter = new ActionCommandConverter(this) }));
     style.Seal();
     return style;
 }
        static KinectCursorVisualizer()
        {
            // Set default style key to be this control type
            DefaultStyleKeyProperty.OverrideMetadata(typeof(KinectCursorVisualizer), new FrameworkPropertyMetadata(typeof(KinectCursorVisualizer)));

            // Set default style to have FlowDirection be LeftToRight
            var style = new Style(typeof(KinectCursorVisualizer), null);
            style.Setters.Add(new Setter(FlowDirectionProperty, FlowDirection.LeftToRight));
            style.Seal();
            StyleProperty.OverrideMetadata(typeof(KinectCursorVisualizer), new FrameworkPropertyMetadata(style));
        }
Example #5
0
		private void SealedChildren (bool seal)
		{
			Style style = new Style (typeof (UIElement));
			SetterBaseCollection c = style.Setters;
			Setter s = new Setter (Canvas.LeftProperty, 0);

			c.Add (s);

			if (seal)
				style.Seal ();

			// the setter IsSealed status has nothing to do with sealing the style
			Assert.Throws (delegate { s.Property = Canvas.TopProperty; }, typeof (UnauthorizedAccessException));
			Assert.Throws (delegate { s.Value = 10; }, typeof (UnauthorizedAccessException));
		}
Example #6
0
		public void Sealed ()
		{
			Style style = new Style (typeof (UIElement));
			SetterBaseCollection c = style.Setters;
			Setter s = new Setter (Canvas.LeftProperty, 0);

			c.Add (s);

			style.Seal ();

			Assert.Throws (delegate { c.Add (new Setter (Canvas.TopProperty, 0)); }, typeof (Exception));
			Assert.Throws (delegate { c.Insert (0, new Setter (Canvas.TopProperty, 0)); }, typeof (Exception));

			/*Assert.Throws (delegate {*/ c.Remove (s);/* }, typeof (Exception));*/

			Assert.AreEqual (0, c.Count);

			// need to reinitialize things here since the
			// Remove above actually succeeded.
			style = new Style (typeof (UIElement));
			c = style.Setters;
			s = new Setter (Canvas.LeftProperty, 0);

			c.Add (s);

			style.Seal ();

			// lame, this should raise an exception too
			/*Assert.Throws (delegate {*/ c.RemoveAt (0);/* }, typeof (Exception));*/

			Assert.AreEqual (0, c.Count);

			// need to reinitialize things here since the
			// RemoveAt above actually succeeded.
			style = new Style (typeof (UIElement));
			c = style.Setters;
			s = new Setter (Canvas.LeftProperty, 0);

			c.Add (s);

			style.Seal ();

			Assert.Throws (delegate { c[0] = new Setter (Canvas.TopProperty, 0); }, typeof (Exception));
		}
Example #7
0
		void SealEmptySetters (Style s)
		{
			Assert.IsFalse (s.IsSealed, "Style.IsSealed-1");
			Assert.IsFalse (s.Setters.IsSealed, "Setters.IsSealed-1");
			Assert.AreEqual (0, s.Setters.Count, "Setters.Count");
			s.Seal ();
			Assert.IsTrue (s.IsSealed, "Style.IsSealed-2");
			Assert.IsTrue (s.Setters.IsSealed, "Setters.IsSealed-2");
		}
Example #8
0
		public void Seal ()
		{
			Setter setter = new Setter (UIElement.OpacityProperty, 2.0);
			Style s = new Style ();
			Assert.IsFalse (s.IsSealed, "Style.IsSealed-1");
			Assert.IsFalse (s.Setters.IsSealed, "Setters.IsSealed-1");
			Assert.IsFalse (setter.IsSealed, "Setter.IsSealed-1");
			s.Setters.Add (setter);
			Assert.IsFalse (s.IsSealed, "Style.IsSealed-2");
			Assert.IsFalse (s.Setters.IsSealed, "Setters.IsSealed-2");
			Assert.IsTrue (setter.IsSealed, "Setter.IsSealed-2");
			s.Seal ();
			Assert.IsTrue (s.IsSealed, "Style.IsSealed-3");
			Assert.IsTrue (s.Setters.IsSealed, "Setters.IsSealed-3");
			Assert.IsTrue (setter.IsSealed, "Setter.IsSealed-3");
		}
Example #9
0
		public void Sealed_CacheIssue ()
		{
			Style style = new Style (typeof (UIElement));

			style.Seal ();

			// TargetType is not "sealed" and can be modified
			style.TargetType = typeof (FrameworkElement);
			style.TargetType = typeof (SolidColorBrush);

			Assert.IsTrue (style.IsSealed, "Style.IsSealed-1");
			Assert.AreEqual (0, style.Setters.Count, "Setters.Count-1");

			Setter setter = new Setter (Rectangle.HeightProperty, "50");
			Assert.IsFalse (setter.IsSealed, "Setter.IsSealed-1");

			// Since we *never* checked that Setters.IsSealed is true then it's not !?!
			// and we can add a new setter to the sealed style
			style.Setters.Add (setter);
			Assert.AreEqual (1, style.Setters.Count, "Setters.Count-2");
			Assert.IsTrue (setter.IsSealed, "Setter.IsSealed-2");
		}
Example #10
0
		public void Sealed ()
		{
			Style style = new Style (typeof (UIElement));
			Assert.IsFalse (style.IsSealed, "Style.IsSealed-1");
			Assert.IsFalse (style.Setters.IsSealed, "Style.Setters.IsSealed-1");

			style.Seal ();
			Assert.IsTrue (style.IsSealed, "Style.IsSealed-2");
			Assert.IsTrue (style.Setters.IsSealed, "Style.Setters.IsSealed-2");

			// TargetType is not "sealed" and can be modified
			style.TargetType = typeof (FrameworkElement);
			style.TargetType = typeof (SolidColorBrush);

			Setter setter = new Setter (Rectangle.HeightProperty, "50");
			Assert.IsFalse (setter.IsSealed, "Setter.IsSealed-2");

			Assert.Throws<Exception> (delegate {
				style.Setters.Add (setter);
			}, "can't add to sealed style");
		}
Example #11
0
 private static Style CreateDefaultWindowStyle()
 {
     var style = new Style(typeof(Window));
     style.Setters.Add(new Setter(Window.ResizeModeProperty, ResizeMode.NoResize));
     style.Setters.Add(new Setter(Window.ShowInTaskbarProperty, false));
     style.Setters.Add(new Setter(Window.SizeToContentProperty, SizeToContent.WidthAndHeight));
     style.Setters.Add(new Setter(Window.WindowStyleProperty, System.Windows.WindowStyle.SingleBorderWindow));
     style.Setters.Add(new Setter(BindingHelpers.WindowStartupLocationProperty, WindowStartupLocation.CenterOwner));
     style.Seal();
     return style;
 }
 private static Style GetDefaultBlurrerStyle()
 {
     var style = new Style(typeof(Border));
     style.Setters.Add(new Setter(Border.BackgroundProperty, Brushes.Black));
     style.Setters.Add(new Setter(OpacityProperty, 0.2D));
     style.Seal();
     return style;
 }
Example #13
0
		public void SetSealedStyleWithSetterToElement ()
		{
			Setter setter = new Setter (Rectangle.HeightProperty, "50");
			Assert.IsFalse (setter.IsSealed, "Setter.IsSealed-1");

			Style s = new Style (typeof (Rectangle));
			Assert.IsFalse (s.IsSealed, "IsSealed-1");
			Assert.IsFalse (s.Setters.IsSealed, "Setters.IsSealed-1");

			s.Setters.Add (setter);
			Assert.IsTrue (setter.IsSealed, "Setter.IsSealed-2");
			Assert.IsFalse (s.IsSealed, "IsSealed-2");
			Assert.IsFalse (s.Setters.IsSealed, "Setters.IsSealed-2");

			s.Seal ();
			Assert.IsTrue (s.IsSealed, "IsSealed-3");
			Assert.IsTrue (s.Setters.IsSealed, "Setters.IsSealed-3");

			Rectangle r = new Rectangle ();
			r.Style = s;
			Assert.IsTrue (s.IsSealed, "IsSealed-4");
			Assert.IsTrue (s.Setters.IsSealed, "Setters.IsSealed-4");
		}
Example #14
0
		public void SetSealedStyleWithoutSetterToElement_CacheIssue ()
		{
			Style s = new Style (typeof (Rectangle));
			// since we don't check IsSealed before sealing the result is different!

			s.Seal ();
			Assert.IsTrue (s.IsSealed, "IsSealed-2");
			Assert.IsFalse (s.Setters.IsSealed, "Setters.IsSealed-2");

			Rectangle r = new Rectangle ();
			r.Style = s;
			Assert.IsTrue (s.IsSealed, "IsSealed-3");
			Assert.IsFalse (s.Setters.IsSealed, "Setters.IsSealed-3");
		}
        //
        //  This method
        //  1. Updates the theme style cache for the given fe/fce
        //
        internal static void UpdateThemeStyleCache(
            FrameworkElement        fe,
            FrameworkContentElement fce,
            Style                   oldThemeStyle,
            Style                   newThemeStyle,
            ref Style               themeStyleCache)
        {
            Debug.Assert(fe != null || fce != null);

            if (newThemeStyle != null)
            {
                DependencyObject d = fe;
                if (d == null)
                {
                    d = fce;
                }
                newThemeStyle.CheckTargetType(d);
                newThemeStyle.Seal();

#pragma warning disable 6503
                // Check if the theme style has the OverridesDefaultStyle  property set on the target tag or any of its
                // visual triggers. It is an error to specify the OverridesDefaultStyle  in your own ThemeStyle.
                if (StyleHelper.IsSetOnContainer(FrameworkElement.OverridesDefaultStyleProperty, ref newThemeStyle.ContainerDependents, true))
                {
                    throw new InvalidOperationException(SR.Get(SRID.CannotHaveOverridesDefaultStyleInThemeStyle));
                }
                // Check if the theme style has EventHandlers set on the target tag or int its setter collection.
                // We do not support EventHandlers in a ThemeStyle
                if (newThemeStyle.HasEventSetters)
                {
                    throw new InvalidOperationException(SR.Get(SRID.CannotHaveEventHandlersInThemeStyle));
                }
#pragma warning restore 6503
            }

            themeStyleCache = newThemeStyle;

            Style style = null;

            if (fe != null)
            {
                if(ShouldGetValueFromStyle ( FrameworkElement.DefaultStyleKeyProperty ) )
                {
                    style = fe.Style;
                }
            }
            else
            {
                if(ShouldGetValueFromStyle ( FrameworkContentElement.DefaultStyleKeyProperty ) )
                {
                    style = fce.Style;
                }
            }

            // Do theme style property invalidations. Note that some of the invalidations may be callouts
            // that could turn around and query the theme style property on this node. Hence it is essential
            // to update the theme style cache before we do this operation.
            StyleHelper.DoThemeStyleInvalidations(fe, fce, oldThemeStyle, newThemeStyle, style);

            // Now look for triggers that might want their EnterActions or ExitActions
            //  to run immediately.
            StyleHelper.ExecuteOnApplyEnterExitActions(fe, fce, newThemeStyle, ThemeStyleDataField);
        }
Example #16
0
		public void SetSealedStyleWithoutSetterToElement ()
		{
			Style s = new Style (typeof (Rectangle));
			Assert.IsFalse (s.IsSealed, "IsSealed-1");
			Assert.IsFalse (s.Setters.IsSealed, "Setters.IsSealed-1");

			s.Seal ();
			Assert.IsTrue (s.IsSealed, "IsSealed-2");
			Assert.IsTrue (s.Setters.IsSealed, "Setters.IsSealed-2");

			Rectangle r = new Rectangle ();
			r.Style = s;
			Assert.IsTrue (s.IsSealed, "IsSealed-3");
			Assert.IsTrue (s.Setters.IsSealed, "Setters.IsSealed-3");
		}
Example #17
0
 private static Style CreateDefaultStyles() {
     var style = new Style(typeof(VirtualizingTilePanel), null);
     style.Seal();
     return style;
 }
Example #18
0
 private static Style CreateDefaultStyles() {
     var style = new Style(typeof(BetterImage), null);
     style.Setters.Add(new Setter(FlowDirectionProperty, FlowDirection.LeftToRight));
     style.Setters.Add(new Setter(HorizontalContentAlignmentProperty, HorizontalAlignment.Center));
     style.Setters.Add(new Setter(VerticalContentAlignmentProperty, VerticalAlignment.Center));
     style.Seal();
     return style;
 }
 void OnSplashScreenWindowStyleChanged(Style oldValue, Style newValue) {
     if(newValue != null)
         newValue.Seal();
 }
Example #20
0
        /// <summary>
        /// Creates a bound style.
        /// </summary>
        /// <param name="style">The style.</param>
        /// <param name="type">The type.</param>
        /// <param name="name">The name.</param>
        /// <returns></returns>
		public static IBoundElement Style(Style style, BoundType type, string name)
        {
            if(!style.IsSealed) style.Seal();
            return new StyleElement(style, type, name);
        }