我正在尝试在特定列下绘制一条垂直线。所以有人告诉我如何水平和垂直绘制一条线
<Window x:Class="WPFDataGrid.GroupBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="GroupBox" Height="300" Width="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="186"/>
<RowDefinition Height="72"/>
<RowDefinition Height="3*" />
</Grid.RowDefinitions>
<GroupBox Header="Select Option" Height="150" HorizontalAlignment="Left" Name="gb1" VerticalAlignment="Top" Width="250" BorderBrush="Black" BorderThickness="1" Margin="11" Padding="11">
<StackPanel>
<CheckBox Content="Add Cream" Margin="3.5"/>
<CheckBox Content="Add Suger" Margin="3.5"/>
<CheckBox Content="Add Flavering" Margin="3.5"/>
<CheckBox Content="Add Biscuit" Margin="3.5"/>
</StackPanel>
</GroupBox>
<Separator Grid.Row="1" HorizontalAlignment="Center" BorderThickness="1" BorderBrush="Black" />
</Grid>
答案 0 :(得分:1)
您可以使用<Separator/>
Link
或者GridSplitter
Link
这里有两个样本:
<Grid x:Name="grid1">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="259"/>
</Grid.ColumnDefinitions>
<TextBox Grid.Row="0" Text="Some text"/>
<StackPanel Grid.Row="1">
<TextBox Text="Some text"/>
<Separator />
<TextBox Text="2nd text box"/>
</StackPanel>
<TextBox Text="Some Text" Grid.Column="1" />
<GridSplitter Grid.Column="0" Grid.Row="0" Grid.RowSpan="2" Width="3" Background="Black"/>
<GridSplitter Grid.Row="0" Grid.ColumnSpan="2" Width="Auto" Height="3" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Background="Black"/>
</Grid>
答案 1 :(得分:1)
<Grid>
<Grid.Resources>
<Style x:Key="lineStyle" TargetType="Line">
<Setter Property="Stroke" Value="Gray" />
<Setter Property="Stretch" Value="Fill" />
<Setter Property="Grid.ZIndex" Value="100" />
</Style>
<Style x:Key="horizontalLineStyle" TargetType="Line" BasedOn="{StaticResource lineStyle}">
<Setter Property="X2" Value="1" />
<Setter Property="X1" Value="0" />
<Setter Property="VerticalAlignment" Value="Bottom" />
<Setter Property="Grid.ColumnSpan"
Value="{Binding
Path=ColumnDefinitions.Count,
RelativeSource={RelativeSource AncestorType=Grid}}" />
<Setter Property="Stroke" Value="Black"/>
<Setter Property="StrokeThickness" Value="1"/>
</Style>
<Style x:Key="verticalLineStyle" TargetType="Line" BasedOn="{StaticResource lineStyle}">
<Setter Property="Y2" Value="1" />
<Setter Property="HorizontalAlignment" Value="Right" />
<Setter Property="Grid.RowSpan"
Value="{Binding
Path=RowDefinitions.Count,
RelativeSource={RelativeSource AncestorType=Grid}}" />
<Setter Property="Stroke" Value="Black"/>
<Setter Property="StrokeThickness" Value="1"/>
</Style>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Line Style="{StaticResource horizontalLineStyle}" />
<Line Grid.Row="0" Style="{StaticResource horizontalLineStyle}" />
<Line Grid.Row="1" Style="{StaticResource horizontalLineStyle}" />
<Line Grid.Column="0" Style="{StaticResource verticalLineStyle}" />
<Line Grid.Column="1" Style="{StaticResource verticalLineStyle}" />
<Line Grid.Column="2" Style="{StaticResource verticalLineStyle}" />
<Line Grid.Column="3" Style="{StaticResource verticalLineStyle}" />
<Line Grid.Column="4" Style="{StaticResource verticalLineStyle}" />
<Label Content="" Grid.Row="0" Grid.Column="0" HorizontalContentAlignment="Center" FontWeight="Bold" Foreground="White"/>
<Label Content="Dword" Grid.Row="0" Grid.Column="1" HorizontalContentAlignment="Center" FontWeight="Bold" Foreground="White"/>
<Label Content="Words" Grid.Row="0" Grid.Column="2" HorizontalContentAlignment="Center" FontWeight="Bold" Foreground="White"/>
<Label Content="Bytes" Grid.Row="0" Grid.Column="3" HorizontalContentAlignment="Center" FontWeight="Bold" Foreground="White"/>
<Label Content="Bits" Grid.Row="0" Grid.Column="4" HorizontalContentAlignment="Center" FontWeight="Bold" Foreground="White"/>
</Grid>
答案 2 :(得分:0)
很容易。选择网格位置,Y1,Y2表示垂直线,X1,X2表示水平线。以下是垂直线的示例。
<Line Grid.Column="2" Grid.Row="1" Grid.RowSpan="2" Stroke="AliceBlue" StrokeThickness="4" Y1="100" Y2="600" Margin="20,0,0,0"></Line>