【问题标题】:WPF RibbonComboBox items listed verticallyWPF RibbonComboBox 项目垂直列出
【发布时间】:2014-01-03 16:28:01
【问题描述】:

我正在处理一些我有 RibbonComboBox 的 XAML:

<RibbonComboBox SelectionBoxWidth="150" Grid.Row="0">
    <RibbonGallery SelectedItem="{Binding SelectedUtilityRun, Mode=TwoWay}">
        <RibbonGalleryCategory ItemsSource="{Binding UtilityRunLabels}" />
    </RibbonGallery>
</RibbonComboBox>

当它显示时,它会水平显示项目,而不是像我预期的那样垂直显示:

如何设置样式以垂直放置项目?

【问题讨论】:

  • 请问您从哪里获得有关如何使用 RibbonComboBox 的文档?我似乎什么也做不了。另外,您是否碰巧知道是否有任何方法可以从代码中手动填充它? (我对此发表了自己的问题,但没有得到答案。)
  • 对不起,我不记得我在 MSDN 之外从哪里得到它。我不知道您如何使用控件背后的代码从代码中填充它。我们在所有 WPF 工作中都使用 MVVM。

标签: c# wpf ribbon


【解决方案1】:

尝试将RibbonGallery.MaxColumnCount 设置为 1:

<RibbonGallery ... MaxColumnCount="1">

【讨论】:

    【解决方案2】:

    在样式中设置 ItemsPanel 并设置 Orientation=Vertical

    <Style TargetType="RibbonComboBox">
    <Setter Property="ItemsPanel">
    <Setter.Value>
      <ItemsPanelTemplate>
        <StackPanel Orientation="Vertical"
                    VerticalAlignment="Center"
                    HorizontalAlignment="Center"/>
      </ItemsPanelTemplate>
    </Setter.Value>
    

    我希望这会有所帮助。

    【讨论】:

    • 这不起作用。它在项目列表中创建了一个水平居中的堆栈面板;堆栈面板中的项目水平放置。很遗憾,我无法在此处发布图片。
    • 对不起,如果它没有工作。我从未使用或使用过 Ribbon Controls 。但这是我在 Itemscontrol 中设置 ItemPanel 的方式
    猜你喜欢
    • 2018-11-25
    • 1970-01-01
    • 2019-04-30
    • 1970-01-01
    • 2012-07-05
    • 1970-01-01
    • 1970-01-01
    • 2023-03-05
    • 1970-01-01
    相关资源
    最近更新 更多