Grid.ShowGridLines="True" 會同時顯示水平與垂直虛線,無法單獨控制。
在每個 RowDefinition 底部放置一個高度為 1、筆刷為所需顏色的 Border,跨越所有欄位(Grid.ColumnSpan)。
<Grid xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
ShowGridLines="False">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!-- 第 0 列內容 -->
<TextBlock Grid.Row="0" Grid.Column="0" Text="Row 0 Col 0"/>
<TextBlock Grid.Row="0" Grid.Column="1" Text="Row 0 Col 1"/>
<!-- 水平分隔線 -->
<Border Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"
BorderThickness="0,0,0,1" BorderBrush="Gray" VerticalAlignment="Bottom"/>
<TextBlock Grid.Row="1" Grid.Column="0" Text="Row 1 Col 0"/>
<TextBlock Grid.Row="1" Grid.Column="1" Text="Row 1 Col 1"/>
<Border Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"
BorderThickness="0,0,0,1" BorderBrush="Gray" VerticalAlignment="Bottom"/>
<TextBlock Grid.Row="2" Grid.Column="0" Text="Row 2 Col 0"/>
<TextBlock Grid.Row="2" Grid.Column="1" Text="Row 2 Col 1"/>
</Grid>
UserControl 或附加屬性(Attached Property),避免重複 XAML。Grid.RowDefinitions 動態新增 Border。