gpt4 book ai didi

c# - WPF 列表框两个项目并排

转载 作者:太空宇宙 更新时间:2023-11-03 20:36:57 24 4
gpt4 key购买 nike

基本上我想创建一个表单。完成后可能会有点长,所以我想使用列表框,以便表单可以滚动。我想要一个标签,旁边有一个文本框,供用户输入。如何在列表框中并排放置标签和文本框?

此外,如果有人对如何创建表单有任何其他建议,请告诉我。

最佳答案

不要使用 ListBox 添加滚动功能,为此使用 ScrollViewer。

您能否勾勒/绘制一张图片来解释您的想法?

<Grid>
<ScrollViewer>
<Grid ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label Target="{Binding ElementName=textBlock}"
VerticalAlignment="Center">_Name:</Label>
<TextBox Grid.Column="1"
x:Name="textBlock"
VerticalAlignment="Center"
Text="Enter text here" />
</Grid>
<Border Grid.Column="1">
<TextBlock Text="Anything you like" />
</Border>
</Grid>
</ScrollViewer>
</Grid>

还有很多其他选择。例如,在我的示例中,您可以将 ScrollViewer 放在边框内。这将使 Border 的内容而不是整个表单可滚动。关键是确定您希望它看起来像什么以及您希望它如何表现。

最好的方法是在 Expression Blend 等设计器中绘图或制作原型(prototype)。

关于c# - WPF 列表框两个项目并排,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4704554/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com