RibbonApplicationMenu从左到右而不是在彼此之下

时间:2014-12-17 09:04:47

标签: c# wpf menu caliburn.micro ribbon

我们在C#WPF应用中使用Caliburn Micro,我们的标准非常RibbonApplicationMenuView.xaml

<RibbonApplicationMenu x:Class="NatWa.MidOffice.Modules.Shared.Ribbon.RibbonApplicationMenuView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ribbon="clr-namespace:NatWa.MidOffice.Modules.Shared.Ribbon"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    d:DataContext="{d:DesignData RibbonApplicationMenuViewModel}" mc:Ignorable="d">

    <RibbonApplicationMenu.Resources>
        <CollectionViewSource x:Key="SourceItems">
            <CollectionViewSource.Source>
                <ribbon:ViewCollection Source="{Binding Items}"/>
            </CollectionViewSource.Source>
        </CollectionViewSource>
    </RibbonApplicationMenu.Resources>

    <RibbonApplicationMenu.ItemsSource>
        <Binding Source="{StaticResource SourceItems}"/>
    </RibbonApplicationMenu.ItemsSource>

</RibbonApplicationMenu>

使用RibbonApplicationMeuViewModel.cs

using Caliburn.Micro;

namespace NatWa.MidOffice.Modules.Shared.Ribbon
{
    public class RibbonApplicationMenuViewModel : PropertyChangedBase 
    {
        private BindableCollection<RibbonItem> _items;

        public RibbonApplicationMenuViewModel()
        {
            Items = new BindableCollection<RibbonItem>();
        }

        public BindableCollection<RibbonItem> Items
        {
            get { return _items; }
            set
            {
                if (Equals(value, _items)) return;
                _items = value;
                NotifyOfPropertyChange(() => Items);
            }
        }
    }
}

这些项目正如此添加:

private static RibbonApplicationMenuViewModel CreateApplicationMenu(IEventAggregator eventAggregator)
{
    var menu = new RibbonApplicationMenuViewModel();
    menu.Items.Add(new RibbonApplicationMenuItemViewModel<ExitCommand>(i18n.Afsluiten, eventAggregator));
    menu.Items.Add(new RibbonApplicationMenuItemViewModel<CheatSheetCommand>(i18n.CheatSheet, eventAggregator));
    return menu;
}

这会产生以下菜单: enter image description here

然而,我想要的是让这两个项目彼此相邻,就像我制作的以下MS Paint修改一样: enter image description here

有谁知道我应该在Property上使用RibbonApplicationMenu,或者我应该在自定义Style中添加什么?我查看了RibbonApplicationMenu属性,找不到任何明显我应该使用的东西(除非我忽略它)。

1 个答案:

答案 0 :(得分:0)

我认为你应该使用

<RibbonTab> 
<RibbonGroup>
<RibbonMenuItem>

</RibbonMenuItem>
</RibbonGroup>
</RibbonTab> 

以水平方式排列。直接添加项目可能无法提供您的预期结果