我有一個Expander控制元件,里面的網格上面會有一個ListBox“Label視頻源”。我正在嘗試使用網格行定義來實作這一點。然而,我的問題是網格行將所有內容均勻地分開。我希望標簽直接位于 ListBox 的頂部。洗掉定義會導致 ListBox 填滿整個網格,包括覆寫標簽(這對我來說毫無意義,因為標簽在頂部)。
我當前的代碼如下:
<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 也不值得
uj5u.com熱心網友回復:
您必須設定行高;到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>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/498401.html
下一篇:位圖中的位圖
