Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin.forms 在Xamarin中设置FillAndExpand后的固定高度_Xamarin.forms - Fatal编程技术网

Xamarin.forms 在Xamarin中设置FillAndExpand后的固定高度

Xamarin.forms 在Xamarin中设置FillAndExpand后的固定高度,xamarin.forms,Xamarin.forms,我是Xamarin的新手,但我非常喜欢自己使用和构建应用程序。然而,我偶然发现了一个无法解决的问题,它与FillAndExpandvertical选项有关。这是我正在使用的相关XAML代码(精简): 在这里,问题在框架内。没有任何内容,它就像一个符咒,做它应该做的。但是,现在我通过C代码中的主类添加子类,使用如下方式: public Main() { InitializeComponent(); // Setup custom

我是Xamarin的新手,但我非常喜欢自己使用和构建应用程序。然而,我偶然发现了一个无法解决的问题,它与
FillAndExpand
vertical选项有关。这是我正在使用的相关XAML代码(精简):


在这里,问题在框架内。没有任何内容,它就像一个符咒,做它应该做的。但是,现在我通过C代码中的主类添加子类,使用如下方式:

public Main()
        {
            InitializeComponent();

            // Setup custom menu bar height
            // This is not done automatically, as it's a RelativeLayout
            var mainDisplayInfo = DeviceDisplay.MainDisplayInfo;
            var xamarinWidth = mainDisplayInfo.Width / mainDisplayInfo.Density;
            CustomNavigationBar.HeightRequest = xamarinWidth / 2254 * 391;
            
            // Fill some hexagons :)
            var center = new Coords(TILE_SIZE, TILE_SIZE);
            var path = new PointCollection();

            for (var j = 0; j < 6; j++)
            {
                var newCoord = HexagonCorner(center, TILE_SIZE, j);
                path.Add(new Point(newCoord.X, newCoord.Y));
            }
            for (var r = 0; r < 10; r++)
            {
                for (var c = 0; c < 12; c++)
                {
                    Random rnd = new Random();

                    SolidColorBrush brush =
                        new SolidColorBrush(
                            Color.FromRgb(
                                (byte)rnd.Next(255),
                                (byte)rnd.Next (255),
                                (byte)rnd.Next (255)
                            )
                            );

                    var polygon = new Polygon
                    {
                        Points = path,
                        Fill = brush,
                        Stroke = Brush.DarkGray,
                        StrokeThickness = 1,
                    };

                    var x = -TILE_SIZE + TILE_SIZE * Math.Sqrt(3) * c;
                    if (r % 2 == 1)
                    {
                        x += TILE_SIZE / 2 * Math.Sqrt(3);
                    }

                    MainGrid.Children.Add(polygon, Constraint.Constant(x), Constraint.Constant(-TILE_SIZE + TILE_SIZE * 1.5 * r));
                }
            }
        }
public Main()
{
初始化组件();
//设置自定义菜单栏高度
//这不是自动完成的,因为这是一个相对的过程
var main displayinfo=DeviceDisplay.main displayinfo;
var xamarinWidth=mainDisplayInfo.Width/mainDisplayInfo.Density;
CustomNavigationBar.HeightRequest=xamarinWidth/2254*391;
//填充一些六边形:)
var中心=新坐标(瓷砖尺寸、瓷砖尺寸);
var path=new PointCollection();
对于(var j=0;j<6;j++)
{
var newCoord=六角(中心,瓷砖尺寸,j);
Add(新点(newCoord.X,newCoord.Y));
}
对于(var r=0;r<10;r++)
{
对于(var c=0;c<12;c++)
{
随机rnd=新随机();
纯色刷=
新SolidColorBrush(
Color.FromRgb(
(字节)rnd.Next(255),
(字节)rnd.Next(255),
(字节)rnd.Next(255)
)
);
var polygon=新多边形
{
点=路径,
填充=刷子,
笔划=画笔.DarkGray,
冲程厚度=1,
};
var x=-TILE_SIZE+TILE_SIZE*Math.Sqrt(3)*c;
如果(r%2==1)
{
x+=瓷砖尺寸/2*数学Sqrt(3);
}
MainGrid.Children.Add(多边形,约束。常量(x),约束。常量(-TILE_SIZE+TILE_SIZE*1.5*r));
}
}
}
当r从0循环到9时它仍然有效,但是当它从0循环到,比如说,20时,框架会被扩展和扩展,你将不再看到底部的元素。有没有办法防止这种情况发生?因此,在初始加载时,尽可能多地设置高度,然后添加子对象(多边形),而不用担心它会溢出

到目前为止,我尝试过的东西都不管用:

  • 将垂直选项设置为其他选项,如
    Fill
    。不会扩展到整个页面
  • 将RelativeLayout移到框架外。那么六边形就不会显示在画面上了
以下是两张帮助示例图片:。上面的一个显示了它应该是什么样子,但是有更多的六边形。下面的一行是它当前的样子(20行)


提前谢谢

如果你能附上一张说明问题的截图,那会有很大帮助。当然,让我补充一下!是否希望框架填充所有可用空间,而不使整个页面的高度超过屏幕高度?我将使用网格而不是堆栈布局作为外部容器。使用“*”表示包含框架的行的高度,使用固定高度表示其他行的高度,这非常适合,谢谢!用
替换它正是我所需要的,非常感谢!!
public Main()
        {
            InitializeComponent();

            // Setup custom menu bar height
            // This is not done automatically, as it's a RelativeLayout
            var mainDisplayInfo = DeviceDisplay.MainDisplayInfo;
            var xamarinWidth = mainDisplayInfo.Width / mainDisplayInfo.Density;
            CustomNavigationBar.HeightRequest = xamarinWidth / 2254 * 391;
            
            // Fill some hexagons :)
            var center = new Coords(TILE_SIZE, TILE_SIZE);
            var path = new PointCollection();

            for (var j = 0; j < 6; j++)
            {
                var newCoord = HexagonCorner(center, TILE_SIZE, j);
                path.Add(new Point(newCoord.X, newCoord.Y));
            }
            for (var r = 0; r < 10; r++)
            {
                for (var c = 0; c < 12; c++)
                {
                    Random rnd = new Random();

                    SolidColorBrush brush =
                        new SolidColorBrush(
                            Color.FromRgb(
                                (byte)rnd.Next(255),
                                (byte)rnd.Next (255),
                                (byte)rnd.Next (255)
                            )
                            );

                    var polygon = new Polygon
                    {
                        Points = path,
                        Fill = brush,
                        Stroke = Brush.DarkGray,
                        StrokeThickness = 1,
                    };

                    var x = -TILE_SIZE + TILE_SIZE * Math.Sqrt(3) * c;
                    if (r % 2 == 1)
                    {
                        x += TILE_SIZE / 2 * Math.Sqrt(3);
                    }

                    MainGrid.Children.Add(polygon, Constraint.Constant(x), Constraint.Constant(-TILE_SIZE + TILE_SIZE * 1.5 * r));
                }
            }
        }