我正在开发适用于 Windows-10 的通用 Windows 平台应用程序。我有关于列表视图的问题。当我单击并将鼠标悬停在列表视图项目上时,所选区域背景很大。你可以在我的图片中看到。
Code:
<ListView Height="160" Name="lstconfig_option" BorderThickness="0" BorderBrush="#FFB0B7BE" ItemClick="lstconfig_option_ItemClick" IsItemClickEnabled="True" HorizontalAlignment="Stretch">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<WrapGrid Orientation="Horizontal" MaximumRowsOrColumns="10"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Margin" Value="0,0,0,0" />
<Setter Property="Padding" Value="0,0,0,-6" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<ListViewItemPresenter
PointerOverBackground="{ThemeResource SystemControlHighlightListLowBrush}"
SelectedBackground="{ThemeResource SystemControlHighlightListMediumBrush}"
SelectedPointerOverBackground="{ThemeResource SystemControlHighlightListMediumBrush}"
PressedBackground="{ThemeResource SystemControlHighlightListMediumBrush}"
SelectedPressedBackground="{ThemeResource SystemControlHighlightListMediumBrush}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate >
<StackPanel Grid.Row="1" Height="auto" HorizontalAlignment="Stretch" PointerEntered="btnFilter_PointerEntered" PointerExited="btnFilter_PointerExited" ToolTipService.ToolTip="{Binding tooltip_text}" ToolTipService.Placement="Bottom">
<Grid Height="auto">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Grid.ColumnSpan="2" Width="200" VerticalAlignment="Top" HorizontalAlignment="Left">
<TextBlock Name="common_label" Text="{Binding label}" Visibility="{Binding label_Visibility}" FontSize="11" Foreground="#FF0D0C0C" Margin="10,0,0,0" VerticalAlignment="Center" Grid.ColumnSpan="2" SelectionHighlightColor="#FFD44C21" />
<TextBox Name="textbox" Visibility="{Binding Visibility}" FontSize="11" Foreground="#FF0D0C0C" TextWrapping="NoWrap" VerticalAlignment="Center" Margin="10,0,0,0" Grid.ColumnSpan="2" BorderBrush="Black" Background="#FFF6F6F6" HorizontalAlignment="Stretch" SelectionHighlightColor="#FFD44C21"/>
</StackPanel>
</Grid>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Image
列表视图项 has a MinWidth
and MinHeight
默认情况下。通过检查ListViewItem 样式和模板,我们可以找到MinWidth
and MinHeight
属性指定如下。
<Setter Property="MinWidth" Value="{ThemeResource ListViewItemMinWidth}"/>
<Setter Property="MinHeight" Value="{ThemeResource ListViewItemMinHeight}"/>
<x:Double x:Key="ListViewItemMinWidth">88</x:Double>
<x:Double x:Key="ListViewItemMinHeight">44</x:Double>
要减小间隙,您可以设置MinHeight
到你想要的值,例如:
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Margin" Value="0,0,0,0" />
<Setter Property="Padding" Value="0,0,0,-6" />
<Setter Property="MinHeight" Value="20" />
...
</Style>
</ListView.ItemContainerStyle>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)