本文整理汇总了C#中System.Windows.Style.Seal方法的典型用法代码示例。如果您正苦于以下问题:C# Style.Seal方法的具体用法?C# Style.Seal怎么用?C# Style.Seal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Style
的用法示例。
在下文中一共展示了Style.Seal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateStyleCache
// ===========================================================================
// 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);
}
示例2: FontChanged
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;
}));
}
}
}
示例3: CreateItemContainerStyle
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;
}
示例4: KinectCursorVisualizer
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));
}
示例5: SealedChildren
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));
}
示例6: Sealed
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));
}
示例7: SealEmptySetters
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");
}
示例8: Seal
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");
}
示例9: Sealed_CacheIssue
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");
}
示例10: Sealed
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");
}
示例11: CreateDefaultWindowStyle
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;
}
示例12: GetDefaultBlurrerStyle
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;
}
示例13: SetSealedStyleWithSetterToElement
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");
}
示例14: SetSealedStyleWithoutSetterToElement_CacheIssue
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");
}
示例15: UpdateThemeStyleCache
//
// 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);
}