Maui android 捏合手势容器问题

Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 26,946 信誉分 Microsoft 供应商
2024-05-02T08:03:32.58+00:00

你好

 

我使用 Ver 17.10 preview 1 和 Android Ver 34。

 

我尝试添加捏合手势容器,但收到错误消息。

 

如下:

//Error I get
//MainPage.xaml : XamlC error : Failed to resolve assembly: 'PinchGesture, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
// File
// MainPage.xml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="
http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="
http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="RazKmoShed.MainPage" Loaded="MainPage_Loaded" x:Name="myContentPage"
             xmlns:mct="
http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
             xmlns:local="clr-namespace:RazKmoShed;assembly=PinchGesture"
             xmlns:label="clr-namespace:RazKmoShed"
             xmlns:entry="clr-namespace:RazKmoShed"
             FlowDirection="LeftToRight" BackgroundColor="#ECE5DD"  >
<ScrollView x:Name="topscroll" HorizontalScrollBarVisibility="Never" VerticalScrollBarVisibility="Never" >
<local:PinchToZoomContainer>
<VerticalStackLayout x:Name="vLayout" Margin="10" Padding="5" Spacing="5" BackgroundColor="#ECE5DD" >
   . . . . . . . . ...
</VerticalStackLayout>
</local:PinchToZoomContainer>
</ScrollView>
</ContentPage>
// File
// PinchToZoomContainer.cs 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RazKmoShed
{
  public class PinchToZoomContainer : ContentView
  {
    double currentScale = 1;
    double startScale = 1;
    double xOffset = 0;
    double yOffset = 0;
    public PinchToZoomContainer()
    {
        PinchGestureRecognizer pinchGesture = new PinchGestureRecognizer();
        pinchGesture.PinchUpdated += OnPinchUpdated;
        GestureRecognizers.Add(pinchGesture);
    }
    void OnPinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
    {
        if (e.Status == GestureStatus.Started)
        {
            // Store the current scale factor applied to the wrapped user interface element,
            // and zero the components for the center point of the translate transform.
            startScale = Content.Scale;
            Content.AnchorX = 0;
            Content.AnchorY = 0;
        }
        if (e.Status == GestureStatus.Running)
        {
            // Calculate the scale factor to be applied.
            currentScale += (e.Scale - 1) * startScale;
            currentScale = Math.Max(1, currentScale);
            // The ScaleOrigin is in relative coordinates to the wrapped user interface element,
            // so get the X pixel coordinate.
            double renderedX = Content.X + xOffset;
            double deltaX = renderedX / Width;
            double deltaWidth = Width / (Content.Width * startScale);
            double originX = (e.ScaleOrigin.X - deltaX) * deltaWidth;
            // The ScaleOrigin is in relative coordinates to the wrapped user interface element,
            // so get the Y pixel coordinate.
            double renderedY = Content.Y + yOffset;
            double deltaY = renderedY / Height;
            double deltaHeight = Height / (Content.Height * startScale);
            double originY = (e.ScaleOrigin.Y - deltaY) * deltaHeight;
            // Calculate the transformed element pixel coordinates.
            double targetX = xOffset - (originX * Content.Width) * (currentScale - startScale);
            double targetY = yOffset - (originY * Content.Height) * (currentScale - startScale);
            // Apply translation based on the change in origin.
            Content.TranslationX = Math.Clamp(targetX, -Content.Width * (currentScale - 1), 0);
            Content.TranslationY = Math.Clamp(targetY, -Content.Height * (currentScale - 1), 0);
            // Apply scale factor
            Content.Scale = currentScale;
        }
        if (e.Status == GestureStatus.Completed)
        {
            // Store the translation delta's of the wrapped user interface element.
            xOffset = Content.TranslationX;
            yOffset = Content.TranslationY;
        }
    }
  }
}

 

我需要做什么? 请帮助我。谢谢。

 

 

 

此问题整理于:https://learn.microsoft.com/en-us/answers/questions/1634481/maui-for-android-pinch-gesture-container-issue

.NET MAUI
.NET MAUI
一种 Microsoft 开源框架,用于构建跨移动设备、平板电脑、台式机的原生设备应用程序。
47 个问题
0 个注释 无注释
{count} 票

接受的答案
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 36,866 信誉分 Microsoft 供应商
    2024-05-02T08:57:21.89+00:00

    你好,

     

    此错误是由 assembly=PinchGesture 引起的。

     

    根据 XAML Namespaces and Namespace Mapping - WPF .NET Framework | Microsoft Learn 文档中的说明,此属性通常指向 dll 或其他扩展文件。

     

    assembly= The assembly that contains some or all of the referenced CLR namespace. This value is typically just the name of the assembly, not the path, and does not include the extension (such as .dll or .exe). The path to that assembly must be established as a project reference in the project file that contains the XAML you are trying to map. In order to incorporate versioning and strong-name signing, the assembly value can be a string as defined by AssemblyName, rather than the simple string name.

     

    解决方法 1:

     

    xmlns:local="clr-namespace:RazKmoShed;assembly=PinchGesture" 修改为 xmlns:local="clr-namespace:RazKmoShed"

     

    解决方法 2:

     

    xmlns:local="clr-namespace:RazKmoShed;assembly=PinchGesture" 修改为 xmlns:local="clr-namespace:RazKmoShed;assembly=RazKmoShed"

     

     


    如果答案是正确的,请点击“接受答案”并点赞。 如果您对此答案还有其他疑问,请点击“评论”。 注意:如果您想接收相关电子邮件,请按照我们的文档中的步骤启用电子邮件通知 此线程的通知。

    0 个注释 无注释

0 个其他答案

排序依据: 非常有帮助