首页 > 解决方案 > 文本框填充网格行中的所有可用空间

问题描述

我的 UI XAML 代码出现问题。问题是我无法TextBox填写包含它的网格行中的所有可用空间。我读了很多关于类似问题的帖子,它们的摘要是“不要为此使用堆栈面板”和“设置VerticalAlignment="Stretch"”,但这对我不起作用。在我的 XAML 底部附近,您可以看到我一直在尝试拉伸以填充网格行的高度的文本框,以及我希望在评论结束时能够工作的文本框。

拥有VerticalAlignment="Stretch"不会改变 XAML 的行为,并且会产生一行TextBox,就好像我根本没有分配一样VerticalAlignment="Stretch"。这是有或没有 GUI 页面的样子VerticalAlignment="Stretch"

在此处输入图像描述

这是相应的 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>

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

谢谢你。

标签: c#wpf

解决方案


很可能存在一种隐式样式,TextBox即设置默认值Height。如果是这种情况,您需要设置:

Height="NaN"

在你TextBox的为了它伸展。


推荐阅读