英文:
Is InkToolbar available in WinUI 3?
问题
WinUI 3的Figma文件中有InkToolbar,但似乎在WindowsAppSDK NuGet包中不可用。这正确吗?
如果在WinUI3中可用,如何实现它?
谢谢
我尝试实现这个控件,但未成功,并且对它为什么出现在FIGMA设计文件中感到困惑。
英文:
I had a look at the WinUI 3 Figma file and InkToolbar is present, but it doesn't seem to be available in the WindowsAppSDK NuGet package. Is that right?
If it is available for WinUI3, how can it be implemented?
Thanks
I tried implementing the control, but I wasn't able to, and I'm confused as to why it is in the FIGMA design file.
答案1
得分: 1
Inking在WinUI 3的1.4版本中不可用(实验性):既没有InkToolbar,也没有InkCanvas。您可以使用普通的Canvas并在其上绘制形状(线条)来模拟InkCanvas,甚至可以捕获笔压以模拟线条粗细。
以下是一个执行此操作的代码片段:
bool penDown = false;
Point oldPoint;
InkStrokeBuilder inkStrokeBuilder = new InkStrokeBuilder();
List<InkStroke> strokes = new List<InkStroke>();
List<Point> currentStrokePoints;
private void Canvas_PointerPressed(object sender, PointerRoutedEventArgs e)
{
e.Handled = true;
if (e.Pointer.PointerDeviceType == Microsoft.UI.Input.PointerDeviceType.Mouse ||
e.Pointer.PointerDeviceType == Microsoft.UI.Input.PointerDeviceType.Pen)
{
penDown = true;
var pnt = e.GetCurrentPoint(DrawCanvas);
oldPoint = pnt.Position;
}
currentStrokePoints = new List<Point>();
currentStrokePoints.Add(oldPoint);
}
private void DrawCanvas_PointerMoved(object sender, PointerRoutedEventArgs e)
{
if (!penDown) return;
var pnt = e.GetCurrentPoint(DrawCanvas);
Line line = new Line();
line.X1 = oldPoint.X;
line.Y1 = oldPoint.Y;
line.X2 = pnt.Position.X;
line.Y2 = pnt.Position.Y;
line.Stroke = new SolidColorBrush(Colors.Black);
line.StrokeThickness = 2 * pnt.Properties.Pressure;
DrawCanvas.Children.Add(line);
oldPoint = pnt.Position;
currentStrokePoints.Add(pnt.Position);
}
private void DrawCanvas_PointerReleased(object sender, PointerRoutedEventArgs e)
{
penDown = false;
currentStrokePoints.Add(e.GetCurrentPoint(DrawCanvas).Position);
strokes.Add(inkStrokeBuilder.CreateStroke(currentStrokePoints));
}
您还可以稍后使用WinUI 3中提供的InkAnalyzer
。
附:在社区通话中,团队中的某人提到负责Inking的团队“可能会考虑”,具体意思不明。这也可能意味着“不要考虑它”。
英文:
Inking is not available in WinUI 3 as per version 1.4 (experimental): neither is InkToolbar, nor is InkCanvas. You can simulate InkCanvas using a regular Canvas and drawing shapes (lines) on it, you can even trap the pen pressure to simulate the thickness.
Here is a code snippet that does it:
bool penDown = false;
Point oldPoint;
InkStrokeBuilder inkStrokeBuilder = new InkStrokeBuilder();
List<InkStroke> strokes = new List<InkStroke>();
List<Point> currentStrokePoints;
private void Canvas_PointerPressed(object sender, PointerRoutedEventArgs e)
{
e.Handled = true;
if (e.Pointer.PointerDeviceType == Microsoft.UI.Input.PointerDeviceType.Mouse ||
e.Pointer.PointerDeviceType == Microsoft.UI.Input.PointerDeviceType.Pen)
{
penDown = true;
var pnt = e.GetCurrentPoint(DrawCanvas);
oldPoint = pnt.Position;
}
currentStrokePoints = new List<Point>();
currentStrokePoints.Add(oldPoint);
}
private void DrawCanvas_PointerMoved(object sender, PointerRoutedEventArgs e)
{
if (!penDown) return;
var pnt = e.GetCurrentPoint(DrawCanvas);
Line line = new Line();
line.X1 = oldPoint.X;
line.Y1 = oldPoint.Y;
line.X2 = pnt.Position.X;
line.Y2 = pnt.Position.Y;
line.Stroke = new SolidColorBrush(Colors.Black);
line.StrokeThickness = 2 * pnt.Properties.Pressure;
DrawCanvas.Children.Add(line);
oldPoint = pnt.Position;
currentStrokePoints.Add(pnt.Position);
}
private void DrawCanvas_PointerReleased(object sender, PointerRoutedEventArgs e)
{
penDown = false;
currentStrokePoints.Add(e.GetCurrentPoint(DrawCanvas).Position);
strokes.Add(inkStrokeBuilder.CreateStroke(currentStrokePoints));
}
You can also later use InkAnalyzer
, which is available in WinUI 3.
P.S. In one of the Community Calls, someone from the team mentioned that the team who is responsible for inking "might look into it", whatever that might mean. It may also mean "forget about it".
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论