Dockpanel多个文本块大小?

时间:2016-08-26 22:29:08

标签: c# wpf xaml

我想在Dock面板上填充9个文本块。我希望文本块能够填满整个停靠面板。我已将高度设置为自动,将垂直/水平对齐设置为拉伸。

但是,文本块不会填满整个停靠面板。关于什么可能出错的任何想法。感谢

我的dockpanel住在一个网格中。

<Border  DockPanel.Dock="Top" Background="White" BorderBrush="DodgerBlue" BorderThickness="5,5,5,5" CornerRadius="10" Margin="2" Height="700">
            <DockPanel >
                <TextBlock DockPanel.Dock="Top" Name="txtID" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Height="Auto">1</TextBlock>
                <TextBlock DockPanel.Dock="Top" Name="txtOAG"  VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Height="Auto">2</TextBlock>
                <TextBlock DockPanel.Dock="Top" Name="txtFAILURE_ID" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Height="Auto">3</TextBlock>
                <TextBlock DockPanel.Dock="Top" Name="txtWIDTH"  VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Height="Auto">4</TextBlock>
                <TextBlock DockPanel.Dock="Top" Name="txtHeight"  VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Height="Auto">5</TextBlock>
                <TextBlock DockPanel.Dock="Top" Name="txtBARCODE_READ"  VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Height="Auto">6</TextBlock>
                <TextBlock DockPanel.Dock="Top" Name="txtBARCODE_NUM"  VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Height="Auto">7</TextBlock>
                <TextBlock DockPanel.Dock="Top" Name="txtANOMOLY"  VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Height="Auto">8</TextBlock>
                <TextBlock DockPanel.Dock="Top" Name="txtTRACECODE"  VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Height="Auto">9</TextBlock>

            </DockPanel>
        </Border>

1 个答案:

答案 0 :(得分:1)

DockPanel&#34;码头&#34;双方,StackPanel&#34;堆栈&#34;一起。您应该使用Grid

像这样(3行的例子):

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
        <RowDefinition />
    </Grid.RowDefinitions>
    <TextBlock Text="1" />
    <TextBlock Grid.Row="1" Text="2" />
    <TextBlock Grid.Row="2" Text="3" />
</Grid>