這裏是我用來綁定包含體系結構圖像的項目列表的一些XAML代碼。我的圖像顯示正確,但不填充ListViewItem的寬度,儘管高度填充正確。我的圖像也是方形的,所以我知道這不會發生,因爲圖像沒有明顯的扭曲。ListViewItem內容沒有填充寬度
另外,我注意到ListViewItem有一個淺灰色的背景色,它應該是透明的,或者是null/none。
任何人有任何想法如何獲得約束力嗎?
<ListView x:Name="listView_Architecture" SelectionMode="Single" ScrollViewer.VerticalScrollBarVisibility="Disabled" VerticalContentAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Visible" HorizontalContentAlignment="Stretch" SelectionChanged="listView_Architecture_SelectionChanged">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsVisible}" Value="True">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
<DataTrigger Binding="{Binding IsVisible}" Value="False">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
<DataTrigger Binding="{Binding IsSelected, Mode=TwoWay}" Value="True">
<Setter Property="IsSelected" Value="True" />
</DataTrigger>
<DataTrigger Binding="{Binding IsSelected, Mode=TwoWay}" Value="False">
<Setter Property="IsSelected" Value="False" />
</DataTrigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView AllowsColumnReorder="False">
<GridView.ColumnHeaderContainerStyle>
<Style TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="Visibility" Value="Collapsed"/>
</Style>
</GridView.ColumnHeaderContainerStyle>
<GridViewColumn>
<GridViewColumn.CellTemplate>
<DataTemplate>
<Image Stretch="Fill" Source="{Binding SetupImage, Converter={StaticResource ImageToSourceConverter}}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
你可以在這裏粘貼快照,它是什麼樣的UI顯示? –
您是否嘗試過將ListViewItem樣式的HorizontalAlignment設置爲「Stretch」? –