MAUI Grid 行里面如何同时设置横向和纵向滚动条
在MAUI Grid的行中,可以使用ScrollView来同时设置横向和纵向滚动条。以下是一个示例代码:
using Microsoft.Maui.Controls;
public class MainPage : ContentPage
{
public MainPage()
{
var grid = new Grid();
// 创建ScrollView
var scrollView = new ScrollView();
// 创建要添加到ScrollView中的内容
var content = new StackLayout();
// 添加一些内容到StackLayout中
for (int i = 0; i < 20; i++)
{
content.Children.Add(new Label { Text = $"Item {i}" });
}
// 将内容添加到ScrollView中
scrollView.Content = content;
// 将ScrollView添加到Grid的行中
grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Star });
grid.Children.Add(scrollView, 0, 0);
// 设置Grid为页面的内容
Content = grid;
}
}
在上面的示例中,我们创建了一个Grid,并在其中添加了一个ScrollView作为行的内容。然后,我们创建了一个StackLayout,并将一些内容添加到其中。最后,将StackLayout设置为ScrollView的内容。这样就可以同时在横向和纵向上滚动内容了
原文地址: https://www.cveoy.top/t/topic/h0Vf 著作权归作者所有。请勿转载和采集!