Ejemplo n.º 1
0
        private IDisposable SetBrush(Brush brush, Size destinationSize)
        {
            _context.Save();

            var       solid = brush as SolidColorBrush;
            var       linearGradientBrush = brush as LinearGradientBrush;
            var       radialGradientBrush = brush as RadialGradientBrush;
            var       imageBrush          = brush as ImageBrush;
            var       visualBrush         = brush as VisualBrush;
            BrushImpl impl = null;

            if (solid != null)
            {
                impl = new SolidColorBrushImpl(solid, opacityOverride);
            }
            else if (linearGradientBrush != null)
            {
                impl = new LinearGradientBrushImpl(linearGradientBrush, destinationSize);
            }
            else if (radialGradientBrush != null)
            {
                impl = new RadialGradientBrushImpl(radialGradientBrush, destinationSize);
            }
            else if (imageBrush != null)
            {
                impl = new ImageBrushImpl(imageBrush, destinationSize);
            }
            else if (visualBrush != null)
            {
                impl = new VisualBrushImpl(visualBrush, destinationSize);
            }
            else
            {
                impl = new SolidColorBrushImpl(null, opacityOverride);
            }

            _context.SetSource(impl.PlatformBrush);
            return(Disposable.Create(() =>
            {
                impl.Dispose();
                _context.Restore();
            }));
        }
Ejemplo n.º 2
0
        private IDisposable SetBrush(Brush brush, Size destinationSize)
        {
			_context.Save ();

            var solid = brush as SolidColorBrush;
            var linearGradientBrush = brush as LinearGradientBrush;
            var radialGradientBrush = brush as RadialGradientBrush;
            var imageBrush = brush as ImageBrush;
            var visualBrush = brush as VisualBrush;
			BrushImpl impl = null;

			if (solid != null) 
			{
				impl = new SolidColorBrushImpl(solid, opacityOverride);
			} 
			else if (linearGradientBrush != null) 
			{
				impl = new LinearGradientBrushImpl(linearGradientBrush, destinationSize);
			}
            else if (radialGradientBrush != null)
            {
                impl = new RadialGradientBrushImpl(radialGradientBrush, destinationSize);
            }
            else if (imageBrush != null) 
			{
				impl = new ImageBrushImpl(imageBrush, destinationSize);
			} 
			else if (visualBrush != null) 
			{
				impl = new VisualBrushImpl(visualBrush, destinationSize);
			} 
			else 
			{
				impl = new SolidColorBrushImpl(null, opacityOverride);
			}

			_context.SetSource(impl.PlatformBrush);
			return Disposable.Create(() => 
			{
			    impl.Dispose();
				_context.Restore();
			});
        }