简体   繁体   English

如何使用手指在 canvas 上绘图?

[英]How do I draw on canvas using finger?

I'm trying to make kinda drawing thing via .NET Maui.我正在尝试通过 .NET Maui 进行绘图。 I have read the documentation and now I can draw shapes via command.我已经阅读了文档,现在我可以通过命令绘制形状。 But I have no idea how I can do this using touch event (drawing with finger).但我不知道如何使用触摸事件(用手指绘图)来做到这一点。 Do you know how I can make this?你知道我怎么做这个吗? Do you know any guide or documentation about that?您知道有关此的任何指南或文档吗? What I should read?我应该读什么?

You can use .NET MAUI Community Toolkit package and then use its DrawingView .The DrawingView provides a surface that allows for the drawing of lines through the use of touch or mouse interaction.您可以使用.NET MAUI Community Toolkit DrawingView ,然后使用它的DrawingView。DrawingView提供了一个表面,允许通过使用触摸或鼠标交互来绘制线条。

Here's the steps below on how to use it:以下是有关如何使用它的步骤:

1 . 1 . Install the CommunityToolkit.Maui nuget package安装CommunityToolkit.Maui nuget package

2 . 2 . Call the extension method in your MauiProgram.cs file as follows:在 MauiProgram.cs 文件中调用扩展方法,如下所示:

using CommunityToolkit.Maui;

public static class MauiProgram
{
    public static MauiApp CreateMauiApp()
    {
        var builder = MauiApp.CreateBuilder();
        
        // Initialise the toolkit
        builder.UseMauiApp<App>().UseMauiCommunityToolkit();

        // the rest of your logic...
    }
}

3 . 3 . Add the namespace in your Xaml:在 Xaml 中添加命名空间:

  xmlns:views="clr-namespace:CommunityToolkit.Maui.Views;assembly=CommunityToolkit.Maui"

4 . 4 . Finally, consume it in your Xaml like below:最后,在您的 Xaml 中使用它,如下所示:


            <views:DrawingView
                x:Name="DrawView"
                BackgroundColor="LightGray"
                WidthRequest="200"
                HeightRequest="200"
                IsMultiLineModeEnabled="True"
                LineColor="Red"
                LineWidth="1"
                HorizontalOptions="Center" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM