css - WPF UnifromGrid :How to style selected Child with rounded corners like in Explorer

标签 css wpf xaml styles uniformgrid

这是之前提出的一个问题的链接,该问题涉及 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/

相关文章:

html - 为什么边框没有覆盖所有元素

c# - MahApps DateTimePicker 24 小时时间格式

wpf - 在公共(public)库上创建 BaseViewModel

c# - 确定 ListboxItem 在 Canvas 中的位置?

c# - AutoSuggestBox 查询选中的文本框

xaml - 转到 Listivew 项目 DateTemplate Windows Phone 8.1 中的 VisualState

css - 具有自动颜色选择的第 n 个 child ?

javascript - angular ui-grid 基于动态事件的 css

javascript - 有没有办法检测用户的浏览器是否支持@font-face?

.net - 如何在运行时在代码中应用动态样式?