如何使用 ListView 的 ItemContainerStyle 定位 "Selection Box"?
How to position "Selection Box" with ItemContainerStyle of a ListView?
我一直在阅读 this 文档,我想知道是否可以放置容器的选择复选框?具体来说,这里的这个东西:
理想情况下,我希望它在右侧对齐。到目前为止,我已经尝试使用
<ListView.ItemContainerStyle>
<Style TargetType="WHAT DO I WRITE HERE?">
<Setter Property="HorizontalAlignment" Value="Right"/>
</Style>
</ListView.ItemContainerStyle>
具有各种 TargetTypes。甚至可以定位该选择框吗?
老实说,您找错地方了。 ItemContainerStyle
调整了margin
padding
等项目容器的属性listview
。
您需要 style
换 ListViewItem
。幸运的是,我们可以从 MSDN Documentation
的 ListViewItem styles and templates 轻松获得它。
我不会在此处粘贴整个代码,因为它很大,并且会导致您偏离需要调整的实际代码。
从上面link的样式中,选择上面提到的第二种样式,参考下面的代码:
<Border x:Name="MultiSelectSquare"
BorderBrush="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
BorderThickness="2"
Width="20"
Height="20"
Margin="12,0,0,0"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Visibility="Collapsed" >
<Border.Clip>
<RectangleGeometry Rect="0,0,20,20">
<RectangleGeometry.Transform>
<TranslateTransform x:Name="MultiSelectClipTransform"/>
</RectangleGeometry.Transform>
</RectangleGeometry>
</Border.Clip>
<Border.RenderTransform>
<TranslateTransform x:Name="MultiSelectCheckBoxTransform"/>
</Border.RenderTransform>
<FontIcon x:Name="MultiSelectCheck"
FontFamily="{ThemeResource SymbolThemeFontFamily}"
Glyph=""
FontSize="16"
Foreground="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
Visibility="Collapsed"
Opacity="0"/>
</Border>
上面的代码为 SelectionMode="Multiple"
处理了 checkbox
有点 tick mark with border
。
All the changes you want to do must be done in this style and the above code section of the style.
请注意: 我建议不要使用 Visibility
和 Opacity
属性,因为它们是使用 [=23 修改的=].不要担心它们,它们会在运行时改变状态。
我一直在阅读 this 文档,我想知道是否可以放置容器的选择复选框?具体来说,这里的这个东西:
理想情况下,我希望它在右侧对齐。到目前为止,我已经尝试使用
<ListView.ItemContainerStyle>
<Style TargetType="WHAT DO I WRITE HERE?">
<Setter Property="HorizontalAlignment" Value="Right"/>
</Style>
</ListView.ItemContainerStyle>
具有各种 TargetTypes。甚至可以定位该选择框吗?
老实说,您找错地方了。 ItemContainerStyle
调整了margin
padding
等项目容器的属性listview
。
您需要 style
换 ListViewItem
。幸运的是,我们可以从 MSDN Documentation
的 ListViewItem styles and templates 轻松获得它。
我不会在此处粘贴整个代码,因为它很大,并且会导致您偏离需要调整的实际代码。
从上面link的样式中,选择上面提到的第二种样式,参考下面的代码:
<Border x:Name="MultiSelectSquare"
BorderBrush="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
BorderThickness="2"
Width="20"
Height="20"
Margin="12,0,0,0"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Visibility="Collapsed" >
<Border.Clip>
<RectangleGeometry Rect="0,0,20,20">
<RectangleGeometry.Transform>
<TranslateTransform x:Name="MultiSelectClipTransform"/>
</RectangleGeometry.Transform>
</RectangleGeometry>
</Border.Clip>
<Border.RenderTransform>
<TranslateTransform x:Name="MultiSelectCheckBoxTransform"/>
</Border.RenderTransform>
<FontIcon x:Name="MultiSelectCheck"
FontFamily="{ThemeResource SymbolThemeFontFamily}"
Glyph=""
FontSize="16"
Foreground="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
Visibility="Collapsed"
Opacity="0"/>
</Border>
上面的代码为 SelectionMode="Multiple"
处理了 checkbox
有点 tick mark with border
。
All the changes you want to do must be done in this style and the above code section of the style.
请注意: 我建议不要使用 Visibility
和 Opacity
属性,因为它们是使用 [=23 修改的=].不要担心它们,它们会在运行时改变状态。