WPF-烤架间距混乱

发布于 2025-02-12 13:15:40 字数 1162 浏览 1 评论 0原文

我有一个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:

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

趴在窗边数星星i 2025-02-19 13:15:40

您必须设置行高度;到auto(即:最小值)和*(即:剩余空间)。
同样只需要两个行定义。

<Grid>
    <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <Label Grid.Row="0"
           Content="Video Sources" />

    <ListBox Grid.Row="1"
             ItemsSource="{d:SampleData}"
             VerticalAlignement="Top" />
</Grid>

You have to set the rows height ; to auto (ie: minimal value) and * (ie: remaining space).
Also only two rows definition are needed.

<Grid>
    <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <Label Grid.Row="0"
           Content="Video Sources" />

    <ListBox Grid.Row="1"
             ItemsSource="{d:SampleData}"
             VerticalAlignement="Top" />
</Grid>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文