C# NaN不是有效的宽度值

C# NaN不是有效的宽度值,c#,xamarin,xamarin.forms,C#,Xamarin,Xamarin.forms,在Xamarin.Forms 2.3.4.192-pre2中,我创建了一个自定义的ViewCell,它为Xamarin.Forms.ListView的DataTemplate使用网格 加载列表视图时,它会抛出System.ArgumentException:NaN不是宽度的有效值 我已经找到了,但是我不明白为什么宽度会是NaN 错误 System.ArgumentException:NaN不是有效的宽度值 Xamarin.表格.尺寸.尺寸(双倍宽度,双倍高度) Xamarin.Forms.Vis

在Xamarin.Forms 2.3.4.192-pre2中,我创建了一个自定义的
ViewCell
,它为
Xamarin.Forms.ListView的
DataTemplate
使用网格

加载
列表视图
时,它会抛出
System.ArgumentException:NaN不是宽度的有效值

我已经找到了,但是我不明白为什么宽度会是
NaN

错误 System.ArgumentException:NaN不是有效的宽度值

Xamarin.表格.尺寸.尺寸(双倍宽度,双倍高度) Xamarin.Forms.VisualElement.GetSizeRequest(双宽度约束,双高度约束) Xamarin.Forms.VisualElement.Measure(双宽度约束、双高度约束、MeasureFlags标志) Xamarin.Forms.StackLayout.compressionHorizontalLayout(StackLayout.LayoutInformation布局,双宽度约束,双高度约束) Xamarin.Forms.StackLayout.CompressNaiveLayout(StackLayout.LayoutInformation布局、StackOrientation方向、双宽度约束、双高度约束) Xamarin.Forms.StackLayout.CalculateLayout(StackLayout.LayoutInformation布局、双x、双y、双宽度约束、双高度约束、布尔处理器扩展器) Xamarin.Forms.StackLayout.LayoutChildren(双x、双y、双宽、双高) Xamarin.Forms.Layout.UpdateChildrenLayout() Xamarin.Forms.Layout.OnSizeAllocated(双宽双高) Xamarin.Forms.VisualElement.SizeAllocated(双宽双高) Xamarin.Forms.VisualElement.SetSize(双倍宽度,双倍高度) Xamarin.Forms.VisualElement.set_边界(矩形值) Xamarin.Forms.VisualElement.Layout(矩形边界) Xamarin.Forms.Layout.LayoutChildInBoundingRegion(VisualElement子元素,矩形区域) Xamarin.Forms.Grid.LayoutChildren(双x、双y、双宽度、双高度) Xamarin.Forms.Layout.UpdateChildrenLayout() Xamarin.Forms.Layout.OnSizeAllocated(双宽双高) Xamarin.Forms.VisualElement.SizeAllocated(双宽双高) Xamarin.Forms.VisualElement.SetSize(双倍宽度,双倍高度) Xamarin.Forms.VisualElement.set_边界(矩形值) Xamarin.Forms.VisualElement.Layout(矩形边界) Xamarin.Forms.Layout.LayoutChildInBoundingRegion(VisualElement子元素,矩形区域) Xamarin.Forms.Platform.iOS.ViewCellRenderer.ViewTableCell.LayoutSubviews() Xamarin.Forms.Platform.iOS.CellTableViewCell.GetNativeCell(UITableView表格视图、单元格单元格、布尔循环单元格、字符串模板ID) Xamarin.Forms.Platform.iOS.ListViewRenderer.ListViewDataSource.GetCell(UITableView tableView,NSIndexPath indexPath) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)(包装器管理为本机) UIKit.UIApplication.Main(字符串[]参数,IntPtr主体,IntPtr委托)UIApplication.cs:79 UIKit.UIApplication.Main(string[]args,string principalClassName,string delegateClassName)UIApplication.cs:63 MondayPundayApp.iOS.Application.Main(字符串[]args)Main.cs:17

代码 我在GitHub的这个存储库中制作了一个复制品:

列表视图 可视单元
这似乎是与Xamarin.Forms v2.3.4.192-pre2的回归

使用Xamarin.Forms v2.3.3.180时不会引发异常

我通过Bugzilla将bug提交给Xamarin.Forms团队:

更新:此错误已在Xamarin中修复。表单2.3.4.214-pre5添加容器(例如:框架)并指定此容器的宽度

<Frame x:Name="AutoCompleterContainer" Grid.Row="1" WidthRequest="400">
    <telerikInput:RadAutoComplete ....
</Frame>

public class PuzzleCellCardView : ViewCell
{
    Image _puzzleImage;
    Label _punNumberValueLabel;
    Image _questionMarkImage;
    Image _checkImage;

    public PuzzleCellCardView()
    {
        var puzzleImage = new Image
        {
            HeightRequest = 150,
            BackgroundColor = Color.White
        };

        var punNumberTextLabel = new Label
        {
            Text = " Pun Number",
            Style = StyleConstants.LabelStyle
        };

        _punNumberValueLabel = new Label
        {
            Style = StyleConstants.LabelStyle
        };

        var puzzleNumberStackLayout = new StackLayout
        {
            Children = {
                punNumberTextLabel,
                _punNumberValueLabel
            },
            Orientation = StackOrientation.Horizontal,
            BackgroundColor = Color.White
        };

        _questionMarkImage = new Image
        {
            Source = App.ImageConstants.QuestionMark,
            MinimumHeightRequest = 100,
            BackgroundColor = Color.White
        };

        _checkImage = new Image
        {
            Source = App.ImageConstants.Check,
            MinimumHeightRequest = 100,
            BackgroundColor = Color.White
        };

        var whitePuzzleNumberBackgroundBoxView = new BoxView
        {
            BackgroundColor = Color.White
        };

        var cellGridLayout = new Grid
        {
            BackgroundColor = Color.Black,
            Padding = new Thickness(2),
            RowSpacing = 2,
            ColumnSpacing = 1,
            VerticalOptions = LayoutOptions.Fill,

            RowDefinitions = {
                new RowDefinition{ Height = new GridLength (20, GridUnitType.Absolute) },
                new RowDefinition{ Height = new GridLength (150, GridUnitType.Absolute) }
            },
            ColumnDefinitions = {
                new ColumnDefinition{ Width = new GridLength (1, GridUnitType.Star) },
                new ColumnDefinition{ Width = new GridLength (1, GridUnitType.Star) }
            }
        };
        cellGridLayout.Children.Add(whitePuzzleNumberBackgroundBoxView, 0, 0);
        Grid.SetColumnSpan(whitePuzzleNumberBackgroundBoxView, 2);

        cellGridLayout.Children.Add(puzzleNumberStackLayout, 0, 0);
        Grid.SetColumnSpan(puzzleNumberStackLayout, 2);

        cellGridLayout.Children.Add(_puzzleImage, 0, 1);

        cellGridLayout.Children.Add(_checkImage, 1, 1);
        cellGridLayout.Children.Add(_questionMarkImage, 1, 1);

        if (Device.OS == TargetPlatform.Android)
            _puzzleImage.InputTransparent = true;

        View = cellGridLayout;
    }
}
<Frame x:Name="AutoCompleterContainer" Grid.Row="1" WidthRequest="400">
    <telerikInput:RadAutoComplete ....
</Frame>