TextBox 在 UWP 中不会水平拉伸

https://img1.mukewang.com/650560dd000103bc19141023.jpg

蓝色部分是我的文本框,红色部分是我的相关面板。相关面板放置在列表视图中


<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" 但它不起作用。请帮我解决这个问题


慕桂英4014372
浏览 71回答 2
2回答

qq_遁去的一_1

我相信,这是由于缺乏精确的对齐指令,因为相对面板有点保守,以尽量减少内部元素与其布局需求之间的潜在冲突。那么,您可以尝试显式设置左对齐和右对齐,如下所示:...&nbsp;RelativePanel.AlignLeftWithPanel="True"&nbsp;RelativePanel.AlignRightWithPanel="True"&nbsp;...更新:是的,在您的情况下,似乎可以通过使用网格元素来简化布局,因为内部控件太少(只有两个),因此定位它们不是问题。

白板的微信

使用网格而不是相关面板对我有用&nbsp;<Grid Margin="10,10,20,10"&nbsp; HorizontalAlignment="Stretch"&nbsp; VerticalAlignment="Stretch" >&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <Grid.RowDefinitions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <RowDefinition />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <RowDefinition />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </Grid.RowDefinitions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <TextBox&nbsp; BorderThickness="0,0,0,0" BorderBrush="#8888" HorizontalContentAlignment="Stretch"&nbsp; KeyDown="Box_KeyDown"&nbsp; Name="SubTaskTitle" PlaceholderText="+ Subtask" FontSize="16"&nbsp; &nbsp;Margin="0"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <Line Name="Line" Stretch="Fill" Margin="10 0 0 0" Stroke="#8888" X2="1" Opacity="0.2" Grid.Row="1"/>&nbsp; &nbsp; &nbsp; &nbsp; </Grid>但我仍然无法弄清楚为什么它不适用于相关面板,请有人使用相关面板发布答案。
打开App,查看更多内容
随时随地看视频慕课网APP