c# - 更改自定义 ComboBox 样式中的 ItemsPresenter 以显示彼此相邻的项目

标签 c# wpf xaml windows-phone-8.1

我希望 ComboBox 包含图像作为项目(它们将以编程方式添加)。在默认 ComboBox 中,它们是垂直显示的。我想让它们像在 VariableSizedWrapGrid 中那样显示,但我不确定该怎么做。 我有一个用于 ComboBox 样式的 ItemsPresenter,但将其更改为其他任何样式都不会显示任何内容。

或者也许我应该用其他方式(使用 ListView?)。我希望所选项目像在 ComboBox 中一样显示,并在单击后立即显示所有项目(大约 25 个)。

现在的样子:

enter image description here

我想要的:

enter image description here

最佳答案

更改 ItemsPanel 属性:

<ComboBox>
    <ComboBox.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel/>
        </ItemsPanelTemplate>
    </ComboBox.ItemsPanel>
</ComboBox>

如果您想使用类似VariableSizedWrapGrid 的东西,您可以创建自己的实现或查看其他人的作品,例如:VariableSizedWrapGrid for WPF .

关于c# - 更改自定义 ComboBox 样式中的 ItemsPresenter 以显示彼此相邻的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33845031/

相关文章:

c# - “Invalid window handle” 使用 C# .net 框架 4.7.2 中的 FileOpenPicker 和 Microsoft.Windows.SDK.Contracts 而没有 UWP 时出现错误

c# - 如何在 WPF XAML 中将 ControlTemplate Enabled 属性绑定(bind)到不透明度

c# - Xamarin 表格 : How to access button name in XAML from C#?

.net - WPF Singleton ValueConverters 性能影响

c# - T-SQL C# 类锁

c# - 使用多边形注释在图表中绘制

c# - 使用 Automapper 仅映射特定类型

c# - ToggleButton 内容绑定(bind)到它的状态

c# - 更改 UserControl 中的值时,通过 UserControl 的绑定(bind)中断

c# - 在特定位置分割字符串