ListView
我正在我的應用程式中使用水平滾動制作一種圖片輪播。
my 的高度ListView
是系結到視窗的,所以它可以改變。
我的影像總是比視圖的高度大得多,我不知道如何確保影像不會占用比它更多的空間。
(高度應該是 = 的高度ListView
- 的高度Checkbox
- 的高度ScrollBar
)
<ListView x:Name="listView1" Margin="18,226,15,10" ScrollViewer.VerticalScrollBarVisibility="Disabled" >
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical" CanVerticallyScroll="False" >
<CheckBox Content="Select" />
<Image Source="{Binding Source}" Margin="1" VerticalAlignment="Center" >
<Image.InputBindings>
<MouseBinding MouseAction="LeftDoubleClick" Command="{Binding MouseDoubleClickCommand}" CommandParameter="{Binding Source}"/>
</Image.InputBindings>
</Image>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" CanVerticallyScroll="False"></StackPanel>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
uj5u.com熱心網友回復:
問題是 aStackPanel
沒有可用空間的概念。它只是堆疊其子元素,如果沒有足夠的空間容納它們,它們將被包含元素切斷。
為了使您的影像大小適合可用空間,您可以使用Grid
帶有兩行的 a。第一個使用Height
ofAuto
使其只占用CheckBox
所需的空間,第二個使用默認大小的一顆星來占用剩余空間。
在 a 中定義的列和行
Grid
可以利用星型大小按比例分配剩余空間。When Star is selected as the height or width of a row or column, that column or row receives a weighted proportion of the remaining available space.
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<CheckBox Content="Select"/>
<Image Grid.Row="1" Source="{Binding Source}" Margin="1" VerticalAlignment="Center">
<Image.InputBindings>
<MouseBinding MouseAction="LeftDoubleClick" Command="{Binding MouseDoubleClickCommand}" CommandParameter="{Binding Source}"/>
</Image.InputBindings>
</Image>
</Grid>
</DataTemplate>
或者,您可以使用DockPanel
with LastChildFill
set to true
(default)。
如果將
LastChildFill
屬性設定為true
(這是默認設定),則 a 的最后一個子元素DockPanel
始終填充剩余空間,而不管您在最后一個子元素上設定的任何其他停靠值。
<DataTemplate>
<DockPanel>
<CheckBox DockPanel.Dock="Top" Content="Select"/>
<Image Source="{Binding Source}" Margin="1" VerticalAlignment="Center">
<Image.InputBindings>
<MouseBinding MouseAction="LeftDoubleClick" Command="{Binding MouseDoubleClickCommand}" CommandParameter="{Binding Source}"/>
</Image.InputBindings>
</Image>
</DockPanel>
</DataTemplate>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/508539.html
上一篇:我想在一個容器中只顯示4行資料,然后在第二個容器中顯示接下來的4行資料,并借助顫動中的串列ViewBuilder