Wpf 如何更正ListView项目中的奇数右对齐
我有下面的ListView设置,但是视图中的项目总是稍微出现在中心的右侧,即使我尝试水平对齐左侧。使用“选择”时,标签不完全在正确的位置,这一点尤其明显。很难说,但您可以在这个屏幕截图中看到: 在test001上,您可能会发现它更接近右,而不是左选择显示它更容易,但不会被sniptool拾取 xaml是:Wpf 如何更正ListView项目中的奇数右对齐,wpf,xaml,Wpf,Xaml,我有下面的ListView设置,但是视图中的项目总是稍微出现在中心的右侧,即使我尝试水平对齐左侧。使用“选择”时,标签不完全在正确的位置,这一点尤其明显。很难说,但您可以在这个屏幕截图中看到: 在test001上,您可能会发现它更接近右,而不是左选择显示它更容易,但不会被sniptool拾取 xaml是: <ListView x:Name="listImages" ItemsSource="{Binding Images}" SelectionMode="Multiple" >
<ListView x:Name="listImages" ItemsSource="{Binding Images}" SelectionMode="Multiple" >
<ListView.Resources>
<ContextMenu x:Key="elementContextMenu">
<MenuItem Header="_Close" Command="{Binding Source={StaticResource ImagesContextProxy}, Path=DataContext.Close}" CommandParameter="{Binding}"/>
</ContextMenu>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="ContextMenu" Value="{StaticResource elementContextMenu}"/>
</Style>
</ListView.Resources>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Selector.BorderBrush" Value="Cornsilk"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<Label BorderBrush="White" BorderThickness="1.5" HorizontalAlignment="Left" Margin="2" Padding="1" MaxWidth="200" Background="#FF8787EE"
Content="{Binding ImageModel.ImageName}" VerticalAlignment="Center" ToolTip="{Binding ImageModel.ImageName}"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
我想你需要设置Margin=12而不是Margin=2,因为在中间你有4个像素的Margin现在从左控制2px+从右控制2px我只是用相同的数据test001和bmw测试你的代码,它们正好在这里居中。我认为是其他原因造成了这个问题。