-api-id | -api-type |
---|---|
T:Windows.UI.Xaml.Controls.InkToolbarCustomPen |
winrt class |
Represents an InkToolbar pen for which the ink color palette and pen tip properties, such as shape, rotation, and size, are defined by the host app.
To create an app-defined pen and corresponding button on the InkToolbar, use this class in conjunction with InkToolbarCustomPenButton.
Here's a definition of a custom calligraphic pen.
- In code-behind, we first create a custom pen class derived from InkToolbarCustomPen.
A custom pen class must override the CreateInkDrawingAttributesCore method and provide the InkDrawingAttributes for the custom configuration. In this example, we customize the following InkDrawingAttributes:
- PenTip is set to PenTipShape.Circle;
- Size is set to a Windows.Foundation.Size of
(strokeWidth, strokeWidth * 20)
. - Color is set to the SolidColorBrush selected from the palette, or Colors.Black by default.
- PenTipTransform (through Matrix3x2.CreateRotation) is set to rotate the pen tip by 45°.
[!code-csharpCustomCalligraphicPen]
- In markup, we then bind our custom pen class using a {StaticResource} markup extension reference in the CustomPen attribute of the InkToolbarCustomPenButton element (alternatively, you can instantiate the custom pen and assign it to InkToolbarCustomPenButton.CustomPen in code).
You can use the built-in InkToolbarPenConfigurationControl (as shown here) or you can specify a custom InkToolbarPenConfigurationControl definition in the standard InkToolbar pen declaration.
Here's the declaration for the custom pen defined in the previous snippet.
[!code-xamlUI_AddCustomPen]
Here's the definition of CalligraphicPenIcon
from the MainPage.xaml.cs
file of this example.
[!code-csharpCustomCalligraphicPenMain]
Pen and stylus interactions, Add an InkToolbar to a Universal Windows Platform (UWP) app, Get Started Tutorial: Support ink in your UWP app, Windows.UI.Xaml.Controls classes, InkToolbarPenButton, InkToolbarCustomPenButton, DependencyObject, Ink sample (JavaScript), Get Started Tutorial: Support ink in your UWP app, Coloring book sample, Family notes sample