MAUI .NET 8 в iOS -System.ArgumentException: NaN не является допустимым значением шириныIOS

Программируем под IOS
Ответить
Anonymous
 MAUI .NET 8 в iOS -System.ArgumentException: NaN не является допустимым значением ширины

Сообщение Anonymous »

Я создал новый проект MAUI .NET 8 и перенес код проекта форм Xamarin. При попытке запустить проект с помощью симулятора iOS с помощью Jetbrains Rider выдалось приведенное ниже исключение:
System.ArgumentException: NaN не является допустимым значением ширины
в Microsoft.Maui.Graphics.Size..ctor(двойная ширина, двойная высота)
в Microsoft.Maui.ViewHandlerExtensions.GetDesiredSizeFromHandler(IViewHandler viewHandler, Double widthConstraint, Double heightConstraint )
в Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.IView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[ UIKit.UIView, Microsoft.iOS, Version=17.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]].GetDesiredSize(Double widthConstraint, Double heightConstraint)
в Microsoft.Maui.Layouts. LayoutExtensions.ComputeDesiredSize(представление IView, двойное ограничение ширины, двойное ограничение высоты)
в Microsoft.Maui.Controls.VisualElement.MeasureOverride(Double widthConstraint, Double heightConstraint)
at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IView.Measure(Double widthConstraint, Double heightConstraint)
at Microsoft.Maui.Layouts.VerticalStackLayoutManager.Measure(Double widthConstraint, Double heightConstraint)
в Microsoft.Maui.Controls.StackLayoutManager.Measure(Double widthConstraint, Double heightConstraint)
в Microsoft.Maui.Controls.Layout .CrossPlatformMeasure(Double widthConstraint, Double heightConstraint)
в Microsoft.Maui.Platform.MauiView.CrossPlatformMeasure(Double widthConstraint, Double heightConstraint)
в Microsoft .Maui.Platform.MauiView.SizeThatFits(размер CGSize)
в Microsoft.Maui.ViewHandlerExtensions.GetDesiredSizeFromHandler(IViewHandler viewHandler, Double widthConstraint, Double heightConstraint)
at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.ILayout, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.LayoutView, Microsoft. Мауи, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].GetDesiredSize(Double widthConstraint, Double heightConstraint)
в Microsoft.Maui.Layouts.LayoutExtensions.ComputeDesiredSize(представление IView) , Double widthConstraint, Double heightConstraint)
в Microsoft.Maui.Controls.VisualElement.MeasureOverride(Double widthConstraint, Double heightConstraint)
в Microsoft.Maui .Controls.VisualElement.Microsoft.Maui.IView.Measure(Double widthConstraint, Double heightConstraint)
в Microsoft.Maui.Layouts.LayoutExtensions.MeasureContent(IContentView contentView, Thickness inset, Double widthConstraint, Double heightConstraint)
в Microsoft.Maui.Layouts.LayoutExtensions.MeasureContent(IContentView contentView, Double widthConstraint, Double heightConstraint)
в Microsoft.Maui. Controls.ContentPage.Microsoft.Maui.ICrossPlatformLayout.CrossPlatformMeasure(Double widthConstraint, Double heightConstraint)
в Microsoft.Maui.Platform.MauiView.CrossPlatformMeasure(Double widthConstraint, Double heightConstraint)
в Microsoft.Maui.Platform.MauiView.LayoutSubviews()
в Microsoft.Maui.Platform.ContentView.LayoutSubviews()
at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr PrincipalClassName, IntPtr DelegateClassName) в /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs: строка 58
в UIKit.UIApplication.Main(String[] args, Type PrincipalClass, Type DelegateClass) в /Users/builder/azdo/_work/1/s/xamarin-macios/src /UIKit/UIApplication.cs: строка 94
в SKM_MOBILE.Program.Main(String[] args) в /Users/macmini3/Documents/MAUI/SKM_MOBILE/SKM_MOBILE/Platforms/iOS/ Program.cs:line 13
В моем проекте Xamarin я использовал CustomRender. Я просто хотел использовать тот же код в преобразованном проекте MAUI, поэтому я добавил приведенный ниже код в MauiProgram. Файл .cs согласно документации https://learn.microsoft.com/en-gb/dotne ... t-maui-8.0,
handlers.AddCompatibilityRenderer(typeof(CustomButton),
typeof(SKM_MOBILE.iOS.Renderers.ButtonRenderer_IOS));
публичный класс ButtonRenderer_IOS : Microsoft.Maui.Controls.Compatibility.Platform. iOS.ButtonRenderer
{

Код: Выделить всё

bool IsCalledForFirstTime = false;

protected override void OnElementChanged(ElementChangedEventArgs e)

{

base.OnElementChanged(e);

if (Control != null)

{

Control.TitleLabel.LineBreakMode = UILineBreakMode.WordWrap;

Control.TitleLabel.TextAlignment = UITextAlignment.Center;

if (!IsCalledForFirstTime)

{

IsCalledForFirstTime = true;

Control.TouchDown += Control_TouchDown;

Control.TouchUpInside += Control_TouchUp;

Control.TouchDragExit += Control_TouchDragExit;

}

}

}
public CustomButton (ButtonStyle buttonType = ButtonStyle.SystemSpecific)
{

Код: Выделить всё

this.buttonStyle = buttonType;

switch (buttonType)

{

case ButtonStyle.Default:

{

BackgroundColor = Colors.Gray;

CornerRadius = 5;

TextColor = Colors.White;

}

break;

case ButtonStyle.LongTextButton:

{

BackgroundColor = Colors.Transparent;

TextColor = ApplicationButtonBGnTxtColor;

HorizontalOptions = LayoutOptions.Center;

BorderColor = ApplicationButtonBGnTxtColor;

BorderWidth = 2;

CornerRadius = 5;

FontSize = 15;

FontAttributes = FontAttributes.Bold;

Pressed += OnPressed;

Released += OnReleased;

SetAllCaps = false;

Padding = new Thickness(4, 0, 4, 0);

HeightRequest = 40;

}

break;
Я что-то пропустил? Как мне решить эту проблему?

Подробнее здесь: https://stackoverflow.com/questions/786 ... -for-width
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «IOS»