这是之前提出的一个问题的链接,该问题涉及 TreeView:
WPF TreeView: How to style selected items with rounded corners like in Explorer
这是另一个问题的另一个链接,也涉及 ListView:
WPF ListView: How to style selected items with rounded corners like in Explorer
我的问题是:如何在 UniformGrid 上迁移此解决方案?因为我想在我的 UniformGrid 单元格上产生与 2 个示例中所示相同的效果。
这是我的源代码示例:
<Grid VerticalAlignment="Center" HorizontalAlignment="Center" >
<ItemsControl ItemsSource="{Binding ChildrenList}" BorderThickness="0"
HorizontalContentAlignment="Center" VerticalContentAlignment="Center" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="{Binding NumberOfColumns}" HorizontalAlignment=
"Center" Background="Transparent" Margin="4,4,4,4" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Grid>
最佳答案
你已经完成了一半:)
您需要使用 ListBox
而不是 ItemsControl
(因为 ItemsControl
不处理选择并且没有诸如 "所选元素”)。
然后您使用与示例中相同的 ItemsPanel
,以及与您链接到的 ListView
帖子中相同的 ItemContainerStyle
(注意:只需确保将“ItemsControl”/“ListView”和“ListViewItem”中的内容重命名为“ListBox”和“ListBoxItem”):
<ListBox ItemsSource="{Binding ChildrenList}" >
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="{Binding NumberOfColumns}" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<!-- NOTE: "ListBox" and "ListBoxItem": -->
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
...
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
关于css - WPF UnifromGrid :How to style selected Child with rounded corners like in Explorer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19250478/