【发布时间】:2017-08-19 06:14:50
【问题描述】:
如代码所示,我添加了一支圆珠笔,它支持 30 种颜色,但还不够。
colorSelected(Color type) 是通过其他方式得到的,这里不讨论。 现在我想单击圆珠笔,使用我的 colorSelected 进行绘制。 如何?谢谢。
<Grid>
<InkToolbar TargetInkCanvas="{x:Bind inkCanvas}" InitialControls="AllExceptPens" VerticalAlignment="Top">
<InkToolbarBallpointPenButton x:Name="ballpointPen" Click="xxx_Click"/>
<InkToolbarCustomToolButton x:Name="toolButtonColorPicker" Click="ToolButton_ColorPicker">
<Image Height="20" Width="20" Source="ms-appx:///Assets/Palette.png"/>
<ToolTipService.ToolTip>
<ToolTip Content="ColorPicker"/>
</ToolTipService.ToolTip>
</InkToolbarCustomToolButton>
</InkToolbar>
<InkCanvas x:Name="inkCanvas" Margin="0,48,0,0"/>
</Grid>
下面的代码似乎不起作用...
private void xxx_Click(object sender, RoutedEventArgs e)
{
if(bUserDefinedColor)
{
InkDrawingAttributes drawingAttributes = inkCanvas.InkPresenter.CopyDefaultDrawingAttributes();
drawingAttributes.Color = colorSelected;
inkCanvas.InkPresenter.UpdateDefaultDrawingAttributes(drawingAttributes);
}
}
顺便把测试项目上传到GitHubhttps://github.com/hupo376787/Test.git
【问题讨论】:
-
您的代码应该可以工作。你怎么称呼它?
-
@JustinXL 在 InkToolbarBallpointPenButton 单击事件中。 IE。当我点击圆珠笔按钮时,它应该使用我的颜色。
-
它应该可以工作。请在您的点击处理程序中显示完整的源代码。
-
@JustinXL private void xxx_Click(object sender, RoutedEventArgs e) { if(bUserDefinedColor) { InkDrawingAttributes drawingAttributes = inkCanvas.InkPresenter.CopyDefaultDrawingAttributes();绘图属性.Color = colorSelected; inkCanvas.InkPresenter.UpdateDefaultDrawingAttributes(drawingAttributes); } }
-
bUserDefinedColor 是真的