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:
Here is the screenshot of this fancy application:
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;
}
}
}
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: