Volunteer .NET Evangelist

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

The Magic of Pen

Posted on 2006-02-20 23:19  Sheva  阅读(1579)  评论(0编辑  收藏  举报
    In my last blog entry, I talked about the Avalon brushes and RadialGradientBrush in particular. In this episode, I am gonna talk about pen in Avalon, pen as its name indicates can be used to paint the outline of a specified UIElement or ContentElement, in the following code, I just instantiate a simple Ellipse shape and set its stroke with some tailor-made properties:

using System;
using System.Windows;
using System.Windows.Shapes;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace PenDemo
{
    
public class PenDemoWindow : Window
    {
        [STAThread]
        
public static void Main()
        {
            Application app 
= new Application();
            app.Run(
new PenDemoWindow());
        }
        
public PenDemoWindow()
        {
            
// Set the transparent image as the window background, workaround for the black window problem.
            BitmapImage bitmap = new BitmapImage(new Uri("pack://application:,,/workaround_image.jpg"));
            ImageBrush workaroundImage 
= new ImageBrush(bitmap);
            
this.Background = workaroundImage;

            
this.Title = "The Magic of Pen";

            Ellipse ellipse 
= new Ellipse();
            ellipse.Margin 
= new Thickness(20d);
            ellipse.Width 
= 400d;
            ellipse.Height 
= 400d;
            ellipse.Fill 
= Brushes.Green;
            ellipse.Stroke 
= Brushes.Red;
            ellipse.StrokeThickness 
= 80d;
            ellipse.StrokeDashCap 
= PenLineCap.Round;

            DoubleCollection dc 
= new DoubleCollection();
            dc.Add(0d);
            dc.Add(2d);
            ellipse.StrokeDashArray 
= dc;

            
this.Content = ellipse;
            
this.SizeToContent = SizeToContent.WidthAndHeight;
        }
    }
}

    Here is the screenshot of this fancy application: