本文整理汇总了C#中System.Windows.Media.Brush.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# Brush.Clone方法的具体用法?C# Brush.Clone怎么用?C# Brush.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.Brush
的用法示例。
在下文中一共展示了Brush.Clone方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BrushDesignerWindow
public BrushDesignerWindow(object obj, PropertyInfo prop)
{
InitializeComponent();
(GradientGrid.Background as DrawingBrush).RelativeTransform = GGridTrans = new RotateTransform();
GGridTrans.CenterX = 0.5;
GGridTrans.CenterY = 0.5;
isd = new ImageSourceDesigner();
b = prop.GetValue(obj, null) as Brush;
setv = (x) => prop.SetValue(obj, x, null);
if (b.IsFrozen)
{
b = b.Clone();
setv(b);
}
if (b is SolidColorBrush)
{
cmode = Mode.Solid;
}
else if (b is LinearGradientBrush)
{
cmode = Mode.LinearGradient;
}
else if (b is ImageBrush)
{
cmode = Mode.Image;
}
}
示例2: createFadingBrush
Brush createFadingBrush(Brush baseBrush, double duration)
{
var brush = baseBrush.Clone();
brush.BeginAnimation(Brush.OpacityProperty, new DoubleAnimation
{
From = 0,
To = 1,
Duration = TimeSpan.FromMilliseconds(duration)
});
return brush;
}
示例3: CreateMaterial
/// <summary>
/// Creates a material with the specified diffuse, emissive and specular brushes.
/// </summary>
/// <param name="diffuse">The diffuse.</param>
/// <param name="emissive">The emissive.</param>
/// <param name="specular">The specular.</param>
/// <param name="opacity">The opacity.</param>
/// <param name="specularPower">The specular power.</param>
/// <returns></returns>
public static Material CreateMaterial(Brush diffuse, Brush emissive, Brush specular, double opacity, double specularPower)
{
var mg = new MaterialGroup();
if (diffuse != null)
{
diffuse = diffuse.Clone();
diffuse.Opacity = opacity;
mg.Children.Add(new DiffuseMaterial(diffuse));
}
if (emissive != null)
{
emissive = emissive.Clone();
emissive.Opacity = opacity;
mg.Children.Add(new EmissiveMaterial(emissive));
}
if (specular != null)
{
specular = specular.Clone();
specular.Opacity = opacity;
mg.Children.Add(new SpecularMaterial(specular, specularPower));
}
return mg;
}
示例4: GetBorderPen
private static Pen GetBorderPen(Brush border)
{
Pen pen = null;
if (border != null)
{
if (_commonBorderPen == null) // Common case, if non-null, avoid the lock
{
lock (_resourceAccess) // If non-null, lock to create the pen for thread safety
{
if (_commonBorderPen == null) // Check again in case _pen was created within the last line
{
// Assume that the first render of Button uses the most common brush for the app.
// This breaks down if (a) the first Button is disabled, (b) the first Button is
// customized, or (c) BulletChrome becomes more broadly used than just on Button.
//
// If these cons sufficiently weaken the effectiveness of this cache, then we need
// to build a larger brush-to-pen mapping cache.
// If the brush is not already frozen, we need to create our own
// copy. Otherwise we will inadvertently freeze the user's
// BorderBrush when we freeze the pen below.
if (!border.IsFrozen && border.CanFreeze)
{
border = border.Clone();
border.Freeze();
}
Pen commonPen = new Pen(border, 1);
if (commonPen.CanFreeze)
{
// Only save frozen pens, some brushes such as VisualBrush
// can not be frozen
commonPen.Freeze();
_commonBorderPen = commonPen;
}
}
}
}
if (_commonBorderPen != null && border == _commonBorderPen.Brush)
{
pen = _commonBorderPen;
}
else
{
if (!border.IsFrozen && border.CanFreeze)
{
border = border.Clone();
border.Freeze();
}
pen = new Pen(border, 1);
if (pen.CanFreeze)
{
pen.Freeze();
}
}
}
return pen;
}
示例5: ChangeOpacity
/// <summary>
/// Creates a copy of a brush with the specified opacity.
/// </summary>
/// <param name="brush">
/// The brush to copy.
/// </param>
/// <param name="opacity">
/// The opacity.
/// </param>
/// <returns>
/// </returns>
public static Brush ChangeOpacity(Brush brush, double opacity)
{
brush = brush.Clone();
brush.Opacity = opacity;
return brush;
}
示例6: OnRender
protected override void OnRender(DrawingContext drawingContext) {
base.OnRender(drawingContext);
Debug.Assert((overwriteCaretBrush == null) == (caretBrush == null));
if (caretBrush == null) {
caretBrush = classificationFormatMap.DefaultTextProperties.ForegroundBrush;
Debug.Assert(!classificationFormatMap.DefaultTextProperties.ForegroundBrushEmpty);
if (classificationFormatMap.DefaultTextProperties.ForegroundBrushEmpty)
caretBrush = Brushes.Black;
caretBrush = caretBrush.Clone();
overwriteCaretBrush = caretBrush.Clone();
overwriteCaretBrush.Opacity = 0.5;
if (caretBrush.CanFreeze)
caretBrush.Freeze();
if (overwriteCaretBrush.CanFreeze)
overwriteCaretBrush.Freeze();
}
drawingContext.DrawGeometry(caretGeometry.IsOverwriteMode ? overwriteCaretBrush : caretBrush, null, caretGeometry.Geometry);
}
示例7: OnRenderSizeChanged
protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
{
base.OnRenderSizeChanged(sizeInfo);
double width = ActualWidth;
double width005 = width * .005;
double width015 = width * .015;
double width02 = width * .02;
double width995 = width - width005;
double width985 = width - width015;
double height = ActualHeight;
if (Math.Abs(height - 0.0) < double.Epsilon || Math.Abs(width - 0.0) < double.Epsilon)
{
return;
}
double halfWidth = width / 2;
double halfHeight = height / 2;
double quarterWidth = width / 4;
double baseLine = height * .035;
fontSize = height / (1024 / 15);
symbolfontSize = height / (1024 / 70);
ratioToDisplayAngleMultiplier = width / 360 * RADIAN_TO_ANGLE_MULTIPLIER;
baselinePen = new Pen(brush, THICKNESS_BASELINE);
warningPen = new Pen(warningBrush, THICKNESS_BASELINE);
warning2Pen = new Pen(warning2Brush, THICKNESS_BASELINE);
gaugeBrush = brush.Clone();
gaugeBrush.Opacity = .5;
gaugePen = new Pen(gaugeBrush, THICKNESS_BASELINE);
falseHorizonBrush = brush.Clone();
falseHorizonBrush.Opacity = 1;
falseHorizonPen = new Pen(falseHorizonBrush, THICKNESS_BASELINE);
compassLines = new GeometryGroup();
compassText = new GeometryGroup();
directionTop = new Point(halfWidth, 0);
directionBottom = new Point(halfWidth, baseLine);
directionLineTop = new Point(0, 0);
directionLineLeftBoundTop = new Point(quarterWidth, height * 0);
directionLineLeftBoundBottom = new Point(quarterWidth, height * .03);
directionLineRightBoundTop = new Point(halfWidth + quarterWidth, height * 0);
directionLineRightBoundBottom = new Point(halfWidth + quarterWidth, height * .03);
directionLine10Bottom = new Point(0, height * .02);
directionLine90Bottom = new Point(0, height * .03);
directionLine90TextTop = new Point(0, height * .04);
directionLine90FormattedText = new[]
{
new FormattedText("W", CultureInfo.CurrentUICulture,
FlowDirection.LeftToRight, typeface,
fontSize, brush)
{
TextAlignment = TextAlignment.Center
},
new FormattedText("N", CultureInfo.CurrentUICulture,
FlowDirection.LeftToRight, typeface,
fontSize, brush)
{
TextAlignment = TextAlignment.Center
},
new FormattedText("E", CultureInfo.CurrentUICulture,
FlowDirection.LeftToRight, typeface,
fontSize, brush)
{
TextAlignment = TextAlignment.Center
},
new FormattedText("S", CultureInfo.CurrentUICulture,
FlowDirection.LeftToRight, typeface,
fontSize, brush)
{
TextAlignment = TextAlignment.Center
},
new FormattedText("W", CultureInfo.CurrentUICulture,
FlowDirection.LeftToRight, typeface,
fontSize, brush)
{
TextAlignment = TextAlignment.Center
},
new FormattedText("N", CultureInfo.CurrentUICulture,
FlowDirection.LeftToRight, typeface,
fontSize, brush)
{
TextAlignment = TextAlignment.Center
},
new FormattedText("E", CultureInfo.CurrentUICulture,
FlowDirection.LeftToRight, typeface,
fontSize, brush)
{
TextAlignment = TextAlignment.Center
},
new FormattedText("S", CultureInfo.CurrentUICulture,
FlowDirection.LeftToRight, typeface,
fontSize, brush)
{
TextAlignment = TextAlignment.Center
},
new FormattedText("W", CultureInfo.CurrentUICulture,
FlowDirection.LeftToRight, typeface,
fontSize, brush)
{
TextAlignment = TextAlignment.Center
}
};
//.........这里部分代码省略.........
示例8: InitializeBrushes
void InitializeBrushes(out Brush brush, out Brush overwriteBrush, VSTC.IClassificationType classificationType) {
var props = classificationFormatMap.GetTextProperties(classificationType);
if (!props.BackgroundBrushEmpty)
brush = props.BackgroundBrush;
else {
Debug.Assert(!classificationFormatMap.DefaultTextProperties.ForegroundBrushEmpty);
brush = classificationFormatMap.DefaultTextProperties.ForegroundBrush;
if (classificationFormatMap.DefaultTextProperties.ForegroundBrushEmpty)
brush = Brushes.Black;
}
if (brush.CanFreeze)
brush.Freeze();
overwriteBrush = brush.Clone();
overwriteBrush.Opacity = 0.5;
if (overwriteBrush.CanFreeze)
overwriteBrush.Freeze();
}
示例9: SetStaticBrushColor
private void SetStaticBrushColor(string resourceKey, Brush sourceBrush)
{
Resources[resourceKey] = sourceBrush.Clone();
}
示例10: SwapColors
/// <summary>
/// Swap the color of a brush based on a color mapping provided by the ColorCallback</summary>
/// <param name="brush">Original brush</param>
/// <param name="colorCallback">Callback to provide the color mapping</param>
/// <returns>Color-swapped brush</returns>
public static Brush SwapColors(Brush brush, ColorCallback colorCallback)
{
if (colorCallback == null)
{
throw new ArgumentNullException("colorCallback");
}
Brush brush2 = brush;
if (brush != null)
{
brush2 = brush.Clone();
SwapColorsWithoutCloning(brush2, colorCallback);
brush2.Freeze();
}
return brush2;
}
示例11: ViewActionMenuIcon
/// <summary>
/// Initializes a new instance of the <see cref="ViewActionMenuIcon"/> class.
/// </summary>
/// <param name="icon">The icon.</param>
public ViewActionMenuIcon(Brush icon)
{
if (icon == null)
{
Background = Brushes.Transparent;
return;
}
var brush = icon.Clone();
var drawingBrush = brush as DrawingBrush;
if (drawingBrush != null) drawingBrush.Stretch = Stretch.Uniform;
var imageBrush = brush as ImageBrush;
if (imageBrush != null) imageBrush.Stretch = Stretch.Uniform;
Background = brush;
}
示例12: _mapAbsoluteFill
private static Brush _mapAbsoluteFill(Brush fill, Rect bounds) {
if (!(fill is LinearGradientBrush)) return fill;
var brush = (LinearGradientBrush)fill.Clone();
var stops = brush.GradientStops;
var max = bounds.Height;
if (stops == null || max.IsZero()) return fill;
for (var i = 0; i < stops.Count - 1; i++) {
var offset = stops[i].Offset;
if (!(i == 0 && offset.IsZero() || i == stops.Count - 1 && offset.IsOne())) {
offset = (offset < 0 ? max + offset : offset) / max;
}
stops[i] = new GradientStop(stops[i].Color, offset);
}
return brush;
}
示例13: CreateCommonBorderPen
private Brush CreateCommonBorderPen(Brush borderBrush)
{
lock (locker)
{
if (_commonBorderPen == null)
{
if (!borderBrush.IsFrozen && borderBrush.CanFreeze)
{
borderBrush = borderBrush.Clone();
borderBrush.Freeze();
}
var p = new Pen(borderBrush, 1.0);
if (p.CanFreeze)
{
p.Freeze();
_commonBorderPen = p;
}
}
}
return borderBrush;
}