3 using System
.Windows
.Controls
;
4 using System
.Windows
.Ink
;
5 using System
.Windows
.Input
;
6 using System
.Windows
.Input
.StylusPlugIns
;
7 using System
.Windows
.Media
;
11 class HighContrastInkCanvas
: InkCanvas
14 /// Custom InkCanvas element to collect
15 /// and render high contrast ink
17 public HighContrastInkCanvas()
20 // set Color, Width and Height for the inner stroke
21 this.DynamicRenderer
.DrawingAttributes
.Color
= Colors
.Chocolate
;
22 this.DynamicRenderer
.DrawingAttributes
.Width
= 3d
;
23 this.DynamicRenderer
.DrawingAttributes
.Height
= 3d
;
25 // create a second DynamicRenderer
26 outerDynamicRenderer
= new DynamicRenderer();
27 outerDynamicRenderer
.DrawingAttributes
= this.DefaultDrawingAttributes
.Clone();
28 outerDynamicRenderer
.DrawingAttributes
.Color
= Colors
.DarkGreen
;
29 outerDynamicRenderer
.DrawingAttributes
.Width
*= 1.4d
;
30 outerDynamicRenderer
.DrawingAttributes
.Height
*= 1.4d
;
32 // plug the new DynamicRenderer in, so that it can receive
33 // real-time stylus notifications
34 this.StylusPlugIns
.Add(outerDynamicRenderer
);
36 // re-order the RootVisuals of our DynamicRendererd, so that
37 // the inner stroke gets rendered on top of the outer stroke
38 this.InkPresenter
.DetachVisuals(this.DynamicRenderer
.RootVisual
);
39 this.InkPresenter
.AttachVisuals(outerDynamicRenderer
.RootVisual
, outerDynamicRenderer
.DrawingAttributes
);
40 this.InkPresenter
.AttachVisuals(this.DynamicRenderer
.RootVisual
, this.DynamicRenderer
.DrawingAttributes
);
44 /// Occurs when a stroke drawn by the user is added to the Strokes property
46 protected override void OnStrokeCollected(InkCanvasStrokeCollectedEventArgs e
)
48 base.OnStrokeCollected(e
);
50 // create a clone of the collected strokes with new
51 // DrawingAttributes to represent the outline
52 DrawingAttributes daOutline
= GetOutlineDrawingAttributes(e
.Stroke
.DrawingAttributes
);
53 Stroke newStroke
= new Stroke(e
.Stroke
.StylusPoints
.Clone(), daOutline
);
55 // insert the new strokes at the proper location in
56 // the stroke collection so that it will be renderer
57 // behind the original stroke
58 int index
= this.Strokes
.IndexOf(e
.Stroke
);
59 this.Strokes
.Insert(index
, newStroke
);
63 /// Occurs when the current editing mode changes
65 protected override void OnActiveEditingModeChanged(RoutedEventArgs e
)
67 base.OnActiveEditingModeChanged(e
);
68 if (outerDynamicRenderer
== null) return;
70 if (this.ActiveEditingMode
== InkCanvasEditingMode
.Ink
||
71 this.ActiveEditingMode
== InkCanvasEditingMode
.InkAndGesture
||
72 this.ActiveEditingMode
== InkCanvasEditingMode
.GestureOnly
)
74 outerDynamicRenderer
.Enabled
= true;
78 // prevent dynamic ink rendering when ActiveEditingMode
79 // is not one of the inking modes
80 outerDynamicRenderer
.Enabled
= false;
84 /// Creates a new DrawingAttributes instance to represent
85 /// the outline for given DrawingAttributes
87 private DrawingAttributes
GetOutlineDrawingAttributes(DrawingAttributes oirginalDrawingAttributes
)
89 DrawingAttributes newDrawingAttributes
= oirginalDrawingAttributes
.Clone();
91 // set Color, Width and Height for the outer stroke
92 newDrawingAttributes
.Color
= Colors
.DarkGreen
;
93 newDrawingAttributes
.Width
*= 1.4d
;
94 newDrawingAttributes
.Height
*= 1.4d
;
96 return newDrawingAttributes
;
100 /// DynamicRender to render the stroke outline
102 DynamicRenderer outerDynamicRenderer
= null;