簡體   English   中英

WPF - GridRows 間距混亂

[英]WPF - GridRows Spacing Confusion

我有一個Expander控件,里面的網格會有一個ListBox ,上面有一個Label ,上面寫着“視頻源”。 我正在嘗試使用網格行定義來實現這一點。 然而,我的問題是網格行將所有內容均勻地分開。 我希望 label 直接位於列表框的頂部。 刪除定義會導致 ListBox 填滿整個網格,包括覆蓋 Label(這對我來說毫無意義,因為 label 位於頂部)。

我當前的代碼如下:

<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>

代碼產生這個結果。 您可以看到每個控件之間甚至存在間隙。 我想要列表框正上方的視頻源 label:

在此處輸入圖像描述

如果您可以像在 ListView 中那樣設置列名,那就太好了,但據我所知,這是不可能的。 我認為對於只有一列的東西使用 ListView 也不值得

您必須設置行高; 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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM