繁体   English   中英

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

[英]Textbox Filling all available space in Grid Row

我的 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>

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

谢谢你。

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

Height="NaN"

在您的TextBox上以使其拉伸。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM