c# - 文本框填充网格行中的所有可用空间
问题描述
我的 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
的为了它伸展。
推荐阅读
- jwt - 自定义 JWT 生成在 WSO2 3.2.0 中出现异常
- flutter - ffi Utf8.fromUtf8 在 iOS 上实现 opencv c++ 颤振应用程序时出错
- python - 自适应阈值的 OpenCV 输出
- sql - InfluxDB 占位符“空绑定参数”
- mysql - 许多数据条目的最大值
- sequelize.js - Sequelize - 使用 bcrypt 的加密密码更新
- snowflake-cloud-data-platform - 不使用 UNION 的具有递归 CTE 的连接节点
- php - 尝试在 Laravel 中播种表时出错
- c# - 如何在 ReportViewer 类的 PDF 导出中嵌入自定义字体
- javascript - 将文件夹中的图像加载到 HTML 页面中,以便在添加到文件夹时自动显示在画廊/相册中