C# WINDOWS MAUI專案 GridView動態調整版面分割配置
C# WINDOWS MAUI專案 GridView動態調整版面分割配置
GITHUB: https://github.com/jash-git/MAUI_WinAPI_Object_test/tree/main/Code/18
MainPage.xaml code
<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="MauiChangeGridView.MainPage"> <Grid x:Name="FullGrid"> <Grid.RowDefinitions> <RowDefinition Height="*"/> <RowDefinition Height="2*"/> <RowDefinition Height="40" /> </Grid.RowDefinitions> <VerticalStackLayout x:Name="G01" Grid.Row="0" Grid.Column="0" BackgroundColor="Red"> <Label Text="123" TextColor="White" FontSize="30" HorizontalOptions="Center" VerticalOptions="Center"></Label> </VerticalStackLayout> <VerticalStackLayout x:Name="G02" Grid.Row="1" Grid.Column="0" BackgroundColor="Green"> <Label Text="426" TextColor="White" FontSize="30" HorizontalOptions="Center" VerticalOptions="End"></Label> </VerticalStackLayout> <VerticalStackLayout x:Name="G03" Grid.Row="3" Grid.Column="0"> <Button x:Name="Go" Text="Change" HorizontalOptions="Center" VerticalOptions="End" Clicked="Go_Clicked"/> </VerticalStackLayout> </Grid> </ContentPage>
MainPage.xaml.cs code
namespace MauiChangeGridView; public partial class MainPage : ContentPage { int count = 0; public MainPage() { InitializeComponent(); } private void Go_Clicked(object sender, EventArgs e) { G01.IsVisible = false;//隱藏元件 //--- //動態調整版面配置 FullGrid.RowDefinitions[0] = new RowDefinition(new GridLength(0)); FullGrid.RowDefinitions[1] = new RowDefinition(new GridLength(3, GridUnitType.Star)); //---動態調整版面配置 } }