c# - TextBox 在 UWP 中不会水平拉伸
问题描述
蓝色部分是我的文本框,红色是我的相关面板。相关面板放置在列表视图中
<ListView RelativePanel.Below="Line" Name="SubTasksListView" Margin="10,10,10,0" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" ItemsSource="{x:Bind subtasks}" IsItemClickEnabled="True" ItemClick="ItemClick" ItemTemplate="{StaticResource SubTaskDataTemplate}"/>
<DataTemplate x:DataType="data:ZTask" x:Key="SubTaskDataTemplate">
<RelativePanel Margin="10,10,20,10" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Red" >
<TextBox Background="Aqua" BorderThickness="0,0,0,0" BorderBrush="#8888" HorizontalContentAlignment="Stretch" KeyDown="Box_KeyDown" RelativePanel.AlignLeftWithPanel="True" Name="SubTaskTitle" PlaceholderText="+ Subtask" FontSize="16" Margin="0"/>
<Line Name="Line" Stretch="Fill" Margin="10 0 0 0" Stroke="#8888" X2="1" Opacity="0.2" RelativePanel.Below="SubTaskTitle"/>
</RelativePanel>
</DataTemplate>
我试过 HorizontalAlignment="Stretch" 和 HorizontalContentAlignment="Stretch" 但它不起作用。请帮我解决这个问题
解决方案
我相信,这是由于缺乏精确的对齐指令,因为相对面板有点保守,以尽量减少内部元素与其布局需求之间的潜在冲突。那么,您能否尝试显式设置左右对齐方式,如下所示:
... RelativePanel.AlignLeftWithPanel="True" RelativePanel.AlignRightWithPanel="True" ...
Upd:是的,在您的情况下,似乎可以通过使用 Grid 元素来简化布局,因为内部控件太少(只有两个),因此定位它们不是问题。
推荐阅读
- asp.net-core - 如何在 ASP.NET Core 中读取 SOAP 信封头/正文?
- java - KIE Workbench 决策表没有给出任何结果
- c# - Spawn Enemy GameObject 仅适用于相机视图,而相机随玩家游戏对象移动
- python - 如何获得 Cython 中的最大整数值?
- aframe - 带有 aframe.js 和 howler.js 的实体上的空间声音
- android - 我的 RecyclerView 适配器没有通过 Volley Request 响应更新?
- ios - 使用 Firebase 实时数据库填充集合视图
- python - excel2img 给出错误“异常:定位范围 rez-2!A1:A3 失败”
- python - Django 多组权限
- c# - 为什么 gRPC 不维护服务方法调用之间的状态?