Numeric Extensions.Clamp(double, double, double)' 由于其在 xamarin 表单类中的保护级别而无法访问



我正在努力添加音高以放大我的 xamarin 表单内容页面,我正在使用此示例,并且在手机上运行该应用程序时收到此错误:

严重性代码说明项目文件行抑制状态 错误 CS0122"数字扩展名.夹子(双精度、双精度、双精度("由于其保护级别而无法访问 AppName.Forms C:\TFSMOBILE\AppName.NETStandard\AppName.Forms\Pages\PinchToZoomContainer.cs 55 活动

以下是PinchToZoomContainer的代码:

using System;
using Xamarin.Forms;
namespace AppName.Forms.Pages
{
public class PinchToZoomContainer : ContentView
{
double currentScale = 1;
double startScale = 1;
double xOffset = 0;
double yOffset = 0;
public PinchToZoomContainer()
{
var 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.
//error 1:
Content.TranslationX = targetX.Clamp(-Content.Width * (currentScale - 1), 0);
//error 2:
Content.TranslationY = targetY.Clamp(-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;
}
}
}
}

任何帮助都会很棒!!

提前感谢! :)

您在GitHub 上引用的项目使用的是自己的Clamp函数,而不是内部基于表单的函数,由于错误,我认为您缺少此类:

using System;
namespace PinchGesture
{
public static class DoubleExtensions
{
public static double Clamp (this double self, double min, double max)
{
return Math.Min (max, Math.Max (self, min));
}
}
}

回复:https://github.com/xamarin/xamarin-forms-samples/blob/290d8947432fef55852bf381dcaec393d638f150/WorkingWithGestures/PinchGesture/PinchGesture/Extensions/DoubleExtensions.cs

在当前发布的Xamarin Forms版本中,NumericExtensions是内部的。 它将在未来版本中更改为公开。

同时,您可以自己轻松实现 Clamp

return Math.Min(max, Math.Max(value, min));

最新更新