InkToolbar.InitialControls 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置初始化时添加到 InkToolbar 的内置按钮的集合。
此属性替代内置按钮的默认集合。
默认情况下, InkToolbar 由两组不同的按钮类型组成:
- 包含内置绘图的 RadioButton 组 (InkToolbarBallpointPenButton、 InkToolbarPencilButton) 、擦除 (InkToolbarEraserButton) ,并突出显示 (InkToolbarHighlighterButton) 按钮。 此组是 添加 InkToolbarCustomPenButton 和 InkToolbarCustomToolButton 对象的位置。
功能选择相互排斥。
- 包含内置模具的第二组“切换”按钮 (InkToolbarStencilButton) (或 InkToolbarRulerButton 按钮) 。 此处添加了 InkToolbarCustomToggleButton) (自定义切换。
功能相互不排斥,并且可以与其他活动工具同时使用。
public:
property InkToolbarInitialControls InitialControls { InkToolbarInitialControls get(); void set(InkToolbarInitialControls value); };
InkToolbarInitialControls InitialControls();
void InitialControls(InkToolbarInitialControls value);
public InkToolbarInitialControls InitialControls { get; set; }
var inkToolbarInitialControls = inkToolbar.initialControls;
inkToolbar.initialControls = inkToolbarInitialControls;
Public Property InitialControls As InkToolbarInitialControls
属性值
要添加到 InkToolbar 的内置按钮的集合。
示例
指定初始化时显示的内置按钮:
- 将 InitialControls 设置为 None。
- 添加单个按钮。
- 指定 InkToolbar UI 体验,例如默认按钮。 以下示例 (XAML 和代码隐藏) 演示了如何清除 InkToolber 中的默认按钮、添加圆珠笔、铅笔和橡皮擦按钮,并将默认按钮设置为铅笔。
XAML
<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" />
<!-- Clear the default InkToolbar buttons by setting InitialControls to None. -->
<!-- Set the active tool to the pencil button. -->
<InkCanvas x:Name="inkCanvas" />
<InkToolbar x:Name="inkToolbar"
VerticalAlignment="Top"
TargetInkCanvas="{x:Bind inkCanvas}"
InitialControls="None"
ActiveTool="{x:Bind pencilButton}">
<!--
Add only the ballpoint pen, pencil, and eraser.
Note that the buttons are added to the toolbar in the order
defined by the framework, not the order we specify here.
-->
<InkToolbarEraserButton />
<InkToolbarBallpointPenButton />
<InkToolbarPencilButton x:Name="pencilButton"/>
</InkToolbar>
</Grid>
</Grid>
<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}" />
</Grid>
</Grid>
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// Here, we set up InkToolbar event listeners.
/// </summary>
public MainPage_CodeBehind()
{
this.InitializeComponent();
// Add handlers for InkToolbar events.
inkToolbar.Loading += inkToolbar_Loading;
//inkToolbar.Loaded += inkToolbar_Loaded;
}
/// <summary>
/// Handles the Loading event of the InkToolbar.
/// Here, we identify the buttons to include on the InkToolbar.
/// </summary>
/// <param name="sender">The InkToolbar</param>
/// <param name="args">The InkToolbar event data.
/// If there is no event data, this parameter is null</param>
private void inkToolbar_Loading(FrameworkElement sender, object args)
{
// Clear all built-in buttons from the InkToolbar.
inkToolbar.InitialControls = InkToolbarInitialControls.None;
// Add only the ballpoint pen, pencil, and eraser.
// Note that the buttons are added to the toolbar in the order
// defined by the framework, not the order we specify here.
InkToolbarBallpointPenButton ballpoint = new InkToolbarBallpointPenButton();
InkToolbarPencilButton pencil = new InkToolbarPencilButton();
InkToolbarEraserButton eraser = new InkToolbarEraserButton();
inkToolbar.Children.Add(eraser);
inkToolbar.Children.Add(ballpoint);
inkToolbar.Children.Add(pencil);
}
/// <summary>
/// Handle the Loaded event of the InkToolbar.
/// By default, the active tool is set to the first tool on the toolbar.
/// Here, we set the active tool to the pencil button.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void inkToolbar_Loaded(object sender, RoutedEventArgs e)
{
InkToolbarToolButton pencilButton = inkToolbar.GetToolButton(InkToolbarTool.Pencil);
inkToolbar.ActiveTool = pencilButton;
}
注解
默认的内置按钮或通过 InitialControls 指定的按钮不会添加到 Children 属性。
以编程方式添加或在 XAML 中声明的内置或自定义按钮将添加到 Children 属性。
内置按钮在各自的控制组中按预先确定的顺序显示。 自定义按钮按指定顺序添加到相应的控件组,仅次于所有内置按钮。