文本框填充网格行中的所有可用空间

时间:2020-08-25 14:56:32

标签: c# wpf

我的UI XAML代码遇到问题。问题是我无法TextBox来填充包含它的网格行中的所有可用空间。我读了很多关于类似问题的文章,它们的摘要是“不要为此使用堆栈面板”和“设置VerticalAlignment="Stretch"”,但这对我不起作用。在我的XAML底部附近,您可以看到我一直试图拉伸以填充网格行高度的文本框,以及希望在注释末尾进行工作的文本框。

拥有VerticalAlignment="Stretch"不会改变XAML的行为,并且会产生单行TextBox,就好像我根本没有分配VerticalAlignment="Stretch"一样。无论有没有VerticalAlignment="Stretch",GUI页面的外观如下:

enter image description here

这是相应的XAML代码。

<ContentControl x:Class="Analytics.Configuration.UI.DataflowTemplateView"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
            xmlns:local="clr-namespace:ComputersUnlimited.Analytics.Configuration.UI"
            xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
            xmlns:core="http://schemas.cu.net/2011/xaml/presentation/core"
            mc:Ignorable="d" 
            d:DesignHeight="450" d:DesignWidth="800"
            d:DataContext="{d:DesignInstance local:DataflowTemplateViewModel, IsDesignTimeCreatable=True}">

<Grid x:Name="LayoutRoot">

    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    

    <Grid Grid.Row="0" x:Name="Row0">

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <Button Grid.Column="0" Command="{Binding NavigateToPreviousControlCommand}" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0,0,20,0">Back</Button>

        <TextBlock Grid.Column="1" Text="M-Code Template Text" FontSize="20" HorizontalAlignment="Left" VerticalAlignment="Center"/>

    </Grid>

    <!--<TextBox Grid.Row="1"
             TextWrapping="Wrap"
             HorizontalAlignment="Stretch"
             VerticalAlignment="Stretch"
             Margin="0,6,0,6"
             AcceptsReturn="True"
        HorizontalScrollBarVisibility="Disabled"
        VerticalScrollBarVisibility="Auto"/>-->
    <TextBox Grid.Row="1" VerticalAlignment="Stretch"/>

</Grid>

我尝试了所有遇到的建议,但都没有成功。因此,如果您有任何建议,不胜感激。

谢谢。

1 个答案:

答案 0 :(得分:1)

很可能TextBox有一个隐式样式,它设置了默认的Height。如果是这种情况,则需要设置:

Height="NaN"

在您的TextBox上使其伸展。

相关问题