Volunteer .NET Evangelist

A well oiled machine can’t run efficiently, if you grease it with water.
  首页  :: 联系 :: 订阅 订阅  :: 管理

RadialGradientBrush's Coolness

Posted on 2006-02-19 14:16  Sheva  阅读(1618)  评论(2编辑  收藏  举报
    Brush as its name indicates can be used to paint the texture and chrome of a specified ContentElement or UIElement, Avalon comes with tons of different Brushes, one of which called RadialGradientBrush is what I want to demonstrate in the following code:
  
using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace MoveTheGradientCenter
{
    
public class MainWindow : Window
    {
        
private RadialGradientBrush brush;

        [STAThread]
        
public static void Main()
        {
            Application app 
= new Application();
            app.Run(
new MainWindow());
        }

        
public MainWindow()
        {
            Title 
= "Move The Gradient Center";
            brush 
= new RadialGradientBrush(Colors.White, Colors.Black);
            brush.RadiusX 
= brush.RadiusY = 0.1d;
            brush.SpreadMethod 
= GradientSpreadMethod.Reflect;
            
this.Background = brush;
        }

        
protected override void OnMouseMove(MouseEventArgs e)
        {
            Point mousePosition 
= e.GetPosition(this);
            mousePosition.X 
/= ActualWidth;
            mousePosition.Y 
/= ActualHeight;
            brush.Center 
= mousePosition;
        }
    }
}

With some lines of simple code, you can get the intoxicating look and feel of the window chrome:


    Move your mouse around to see the coolness in action:-)