InkToolbarCustomPen 類別

定義

代表筆跡調色盤和畫筆提示屬性的 InkToolbar 畫筆,例如圖形、旋轉和大小,是由主應用程式所定義。

public ref class InkToolbarCustomPen : DependencyObject
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 196608)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class InkToolbarCustomPen : DependencyObject
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 196608)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public class InkToolbarCustomPen : DependencyObject
Public Class InkToolbarCustomPen
Inherits DependencyObject
繼承
Object Platform::Object IInspectable DependencyObject InkToolbarCustomPen
屬性

Windows 需求

裝置系列
Windows 10 Anniversary Edition (已於 10.0.14393.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v3.0 引進)

範例

以下是自訂書法手寫筆的定義。

  1. 在程式碼後置中,我們會先建立衍生自 InkToolbarCustomPen 的自訂畫筆類別。

自訂畫筆類別必須覆寫 CreateInkDrawingAttributesCore 方法,並提供 InkDrawingAttributes 作為自訂群組態。 在此範例中,我們會自訂下列 InkDrawingAttributes

using System.Numerics;
using Windows.UI;
using Windows.UI.Input.Inking;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;

namespace Ink_Basic_InkToolbar
{
    class CalligraphicPen : InkToolbarCustomPen
    {

        public CalligraphicPen()
        {
        }

        protected override InkDrawingAttributes CreateInkDrawingAttributesCore(Brush brush, double strokeWidth)
        {
            InkDrawingAttributes inkDrawingAttributes = new InkDrawingAttributes();
            inkDrawingAttributes.PenTip = PenTipShape.Circle;
            inkDrawingAttributes.Size = new Windows.Foundation.Size(strokeWidth, strokeWidth * 20);
            SolidColorBrush solidColorBrush = brush as SolidColorBrush;
            if (solidColorBrush != null)
            {
                inkDrawingAttributes.Color = solidColorBrush.Color;
            }
            else
            {
                inkDrawingAttributes.Color = Colors.Black;
            }
            Matrix3x2 matrix = Matrix3x2.CreateRotation(.785f);
            inkDrawingAttributes.PenTipTransform = matrix;

            return inkDrawingAttributes;
        }
    }
}
  1. 在標記中,接著我們會使用InkToolbarCustomPenButton元素之CustomPen屬性中的{StaticResource} 標記延伸參考 (來系結自訂畫筆類別,或者,您也可以在程式碼) 中具現化自訂畫筆,並將其指派給InkToolbarCustomPenButton.CustomPen

您可以使用內建的 InkToolbarPenConfigurationControl (,如這裡所示) ,或者您可以在標準InkToolbar畫筆宣告中指定自訂InkToolbarPenConfigurationControl定義。

以下是先前程式碼片段中定義的自訂手寫筆宣告。

<!-- Set up locally defined resource dictionary. -->
<Page.Resources>
    <!-- Add the custom CalligraphicPen to the page resources. -->
    <local:CalligraphicPen x:Key="CalligraphicPen" />
    <!-- Specify the colors for the palette of the custom pen. -->
    <BrushCollection x:Key="CalligraphicPenPalette">
        <SolidColorBrush Color="Blue" />
        <SolidColorBrush Color="Red" />
    </BrushCollection>
</Page.Resources>

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <StackPanel x:Name="HeaderPanel" Orientation="Horizontal" Grid.Row="0">
        <TextBlock x:Name="Header" 
                   Text="Basic ink sample" 
                   Style="{ThemeResource HeaderTextBlockStyle}" 
                   Margin="10,0,0,0" />
    </StackPanel>
    <Grid Grid.Row="1">
        <Image Source="Assets\StoreLogo.png" />
        <InkCanvas x:Name="inkCanvas" />
        <InkToolbar x:Name="inkToolbar" 
                    VerticalAlignment="Top" 
                    TargetInkCanvas="{x:Bind inkCanvas}">
            <InkToolbarCustomPenButton 
                CustomPen="{StaticResource CalligraphicPen}"
                MinStrokeWidth="1" MaxStrokeWidth="3" SelectedStrokeWidth="2"
                Palette="{StaticResource CalligraphicPenPalette}"
                SelectedBrushIndex ="1"
                ToolTipService.ToolTip="Calligraphic pen">                    
                <SymbolIcon Symbol="{x:Bind CalligraphicPenIcon}"/>                    
                <InkToolbarCustomPenButton.ConfigurationContent>
                    <InkToolbarPenConfigurationControl />
                </InkToolbarCustomPenButton.ConfigurationContent>
            </InkToolbarCustomPenButton>                
        </InkToolbar>
    </Grid>
</Grid>

以下是此範例檔案 MainPage.xaml.cs 中的 定義 CalligraphicPenIcon

namespace Ink_Basic_InkToolbar
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage_AddCustomPen : Page
    {
        // Icon for calligraphic pen custom button.
        Symbol CalligraphicPenIcon = (Symbol)0xEDFB;

        public MainPage_AddCustomPen()
        {
            this.InitializeComponent();
        }
    }
}

備註

若要在 InkToolbar上建立應用程式定義的畫筆和對應的按鈕,請搭配 InkToolbarCustomPenButton使用此類別。

建構函式

InkToolbarCustomPen()

初始化 InkToolbarCustomPen 類別的新實例。

屬性

Dispatcher

取得這個 物件相關聯的 CoreDispatcherCoreDispatcher代表可在 UI 執行緒上存取DependencyObject的功能,即使程式碼是由非 UI 執行緒起始也一樣。

(繼承來源 DependencyObject)

方法

ClearValue(DependencyProperty)

清除相依性屬性的本機值。

(繼承來源 DependencyObject)
CreateInkDrawingAttributes(Brush, Double)

擷取用於InkToolbarPenConfigurationControlInkToolbarCustomPen屬性。

CreateInkDrawingAttributesCore(Brush, Double)

在衍生類別中覆寫時,擷取用來指定InkToolbarCustomPenConfigurationContentInkDrawingAttributes物件。

這個方法不是由應用程式程式碼呼叫。

GetAnimationBaseValue(DependencyProperty)

傳回為相依性屬性建立的任何基底值,如果動畫未使用中,則適用此屬性。

(繼承來源 DependencyObject)
GetValue(DependencyProperty)

DependencyObject傳回相依性屬性的目前有效值。

(繼承來源 DependencyObject)
ReadLocalValue(DependencyProperty)

如果已設定本機值,則傳回相依性屬性的本機值。

(繼承來源 DependencyObject)
RegisterPropertyChangedCallback(DependencyProperty, DependencyPropertyChangedCallback)

註冊通知函式,以接聽此DependencyObject實例上特定DependencyProperty的變更。

(繼承來源 DependencyObject)
SetValue(DependencyProperty, Object)

設定 DependencyObject上相依性屬性的本機值。

(繼承來源 DependencyObject)
UnregisterPropertyChangedCallback(DependencyProperty, Int64)

取消先前透過呼叫 RegisterPropertyChangedCallback註冊的變更通知。

(繼承來源 DependencyObject)

適用於

另請參閱