C# maui scrollview XAML 兩欄 範例
C# maui scrollview XAML 兩欄 範例
01.這個示例中,我們使用了一個 ScrollView 包裹著一個 StackLayout,而 StackLayout 則包含了兩個 StackLayout,每個 StackLayout 代表一列。在每個 StackLayout 中,我們放置了幾個 Label 作為示例項目。這樣,當內容超出屏幕時,ScrollView 將允許用戶進行滾動。
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="YourNamespace.MainPage">
<ScrollView>
<StackLayout Orientation="Horizontal">
<!-- 第一列 -->
<StackLayout>
<Label Text="項目 1" />
<Label Text="項目 2" />
<Label Text="項目 3" />
</StackLayout>
<!-- 第二列 -->
<StackLayout>
<Label Text="項目 4" />
<Label Text="項目 5" />
<Label Text="項目 6" />
</StackLayout>
</StackLayout>
</ScrollView>
</ContentPage>
02.這個範例會建立一個 ScrollView,其中包含一個 Grid。Grid 將內容劃分為兩欄和兩行。第一欄和第二欄分別包含一個 Label,用於顯示欄位標題和內容。
您可以根據需要修改這個範例,例如:
新增更多欄位和行。
使用其他控制項來顯示欄位內容。
設定 Grid 的屬性,例如欄位和行的寬度和高度。
<ScrollView>
<Grid>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<Label Text="第一欄" Grid.Column="0" Grid.Row="0" />
<Label Text="第一欄內容" Grid.Column="0" Grid.Row="1" />
<Label Text="第二欄" Grid.Column="1" Grid.Row="0" />
<Label Text="第二欄內容" Grid.Column="1" Grid.Row="1" />
</Grid>
</ScrollView>