在Xamarin.Forms中制作方形按钮网格可以通过使用Grid布局和自定义按钮样式来实现。下面是一个实现方形按钮网格的示例代码:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
</Grid>
for (int row = 0; row < 3; row++)
{
for (int column = 0; column < 3; column++)
{
Button button = new Button
{
Text = "Button",
Style = (Style)Application.Current.Resources["SquareButtonStyle"]
};
button.Clicked += Button_Clicked;
Grid.SetRow(button, row);
Grid.SetColumn(button, column);
grid.Children.Add(button);
}
}
<Style x:Key="SquareButtonStyle" TargetType="Button">
<Setter Property="BackgroundColor" Value="LightBlue" />
<Setter Property="TextColor" Value="White" />
<Setter Property="CornerRadius" Value="0" />
<Setter Property="HeightRequest" Value="100" />
<Setter Property="WidthRequest" Value="100" />
</Style>
这样,你就可以在Xamarin.Forms中制作一个方形按钮网格了。你可以根据需要调整按钮的样式和布局。
领取专属 10元无门槛券
手把手带您无忧上云