WPF-烤架间距混乱
我有一个expander
控制,并且内部的网格将具有listbox
,其中label
在上面写着“视频源”。我正在尝试使用网格行定义来实现这一目标。但是,我的问题是网格行均匀地分开。我希望该标签直接位于ListBox的顶部。删除definiton会导致列表框填充整个网格,包括盖上标签(这对我来说是没有意义的,因为标签在顶部)。
我当前的代码如下:
<Expander HorizontalAlignment="Left" Height="434" Header="Expander" ExpandDirection="Left" Margin="651,8,0,8">
<Grid Background="#FF252525" ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Label Content="Video Sources" Grid.Row="0"/>
<ListBox Grid.Row="1" d:ItemsSource="{d:SampleData}">
</ListBox>
</Grid>
</Expander>
代码产生此结果。您可以看到每个控件之间甚至都有差距。我希望视频源在列表框上方标签:
如果您可以像在ListView,但是据我所知,这是不可能的。我认为使用listView仅有一个只有一个列的东西,这是不值得的
I have an Expander
control, and the grid inside will have a ListBox
with a Label
on top of it saying 'Video Sources'. I am attempting to use Grid Row Definitions to achieve this. My issue however is that the grid rows separate everything evenly. I want the label to be directly on top of the ListBox. Removing the definitons causes the ListBox to fill up the entire grid including covering up the Label (which makes no sense to me as the label is on top).
My current code is below:
<Expander HorizontalAlignment="Left" Height="434" Header="Expander" ExpandDirection="Left" Margin="651,8,0,8">
<Grid Background="#FF252525" ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Label Content="Video Sources" Grid.Row="0"/>
<ListBox Grid.Row="1" d:ItemsSource="{d:SampleData}">
</ListBox>
</Grid>
</Expander>
The code produces this result. You can see there are even gaps between each control. I want the video sources label right above the listbox:
It would be nice if you could set the column name like in a ListView, however as far as I am aware that is not possible. I don't think it's worth using a ListView for something that will only have a single column, either
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须设置行高度;到
auto
(即:最小值)和*
(即:剩余空间)。同样只需要两个行定义。
You have to set the rows height ; to
auto
(ie: minimal value) and*
(ie: remaining space).Also only two rows definition are needed.