comparison MetroWpf/MetroWpf.Xaml/Adorners/NotesAdorner.cs @ 15:060f02cd4591

Initial commit, pre airport work
author stevenh7776 stevenhollidge@hotmail.com
date Mon, 12 Mar 2012 23:05:21 +0800
parents
children
comparison
equal deleted inserted replaced
14:741981715d94 15:060f02cd4591
1 using System.Globalization;
2 using System.Windows;
3 using System.Windows.Documents;
4 using System.Windows.Media;
5 using MetroWpf.Xaml.Styles;
6
7 namespace MetroWpf.Xaml.Adorners
8 {
9 public class NotesAdorner : Adorner
10 {
11 public NotesAdorner(UIElement adornedElement)
12 : base(adornedElement)
13 {
14 NoteBrush = new SolidColorBrush(AccentColors.Black);
15 NoteWidth = 70;
16 NoteHeight = 30;
17
18 TextBrush = new SolidColorBrush(AccentColors.White);
19 Text = "Adorner!";
20 TextTypeface = new Typeface("Segoe UI");
21 }
22
23 public SolidColorBrush NoteBrush { get; set; }
24 public double NoteWidth { get; set; }
25 public double NoteHeight { get; set; }
26
27 public SolidColorBrush TextBrush { get; set; }
28 public string Text { get; set; }
29 public Typeface TextTypeface { get; set; }
30
31 protected override void OnRender(DrawingContext drawingContext)
32 {
33 Rect adornedElementRect =
34 new Rect(this.AdornedElement.DesiredSize);
35
36 var noteContainer =
37 DrawContainer(drawingContext, adornedElementRect);
38
39 DrawMessageText(
40 drawingContext,
41 noteContainer.Left,
42 noteContainer.Top);
43 }
44
45 private Rect DrawContainer(
46 DrawingContext drawingContext,
47 Rect adornedElementRect)
48 {
49 // border and fill color
50 SolidColorBrush renderBrush = NoteBrush;
51 renderBrush.Opacity = 0.2;
52 Pen renderPen = new Pen(NoteBrush, 1.5);
53
54 // location and sizing
55 double xOffset = 20;
56 double yOffset = 0;
57 double renderRadius = 5.0;
58
59 Point topLeftPosition = new Point(
60 adornedElementRect.Right + xOffset,
61 adornedElementRect.Top + yOffset);
62
63 Point bottomRightPosition = new Point(
64 adornedElementRect.Right + xOffset + NoteWidth,
65 adornedElementRect.Top + NoteHeight);
66
67 Rect noteContainer = new Rect(
68 topLeftPosition,
69 bottomRightPosition);
70
71 //Add to visual tree (should we add to logical tree as well?)
72 drawingContext.DrawRoundedRectangle(
73 renderBrush,
74 renderPen,
75 noteContainer,
76 renderRadius,
77 renderRadius);
78
79 return noteContainer;
80 }
81
82 private void DrawMessageText(
83 DrawingContext drawingContext,
84 double left,
85 double top)
86 {
87 FormattedText formattedText = new FormattedText(
88 Text,
89 CultureInfo.InvariantCulture,
90 FlowDirection.LeftToRight,
91 TextTypeface,
92 12,
93 TextBrush);
94
95 Point topLeftPosition = new Point(
96 left + 8,
97 top + 4);
98
99 drawingContext.DrawText(
100 formattedText,
101 topLeftPosition);
102 }
103 }
104 }