开发者

WPF RibbonControlsLibrary RibbonSplitButton Items issue

I am using a RibbonSplitButton to with menuitems in its dropdown to mimic visual studio's undo redo button. We have the undo redo stacks and I have a dependencypropertychanged event handler that will update the UI based on the stacks. The problem is, the splitbutton's items property is using a Collection, and even though its collection of items are in the right order, it won't display them as they are ordered by index.

I will provide some examples below to explain this better:

Code:

private static void UndoRedoUpdated(DependencyObject obj, DependencyPropertyChangedEventArgs args)
    {
        VO3Main main = (VO3Main)Application.Current.MainWindow;
        MenuItem item;
        int dif;

        if (main.UndoCommands != null)
        {
            dif = main.UndoCommands.Count - main._undoMenu.Items.Count;
            if (dif > 0)
            {
                for (int i = dif - 1; i >= 0; i--)
                {
                    item = new MenuItem();
                    item.Header = main.UndoCommands[i].Name;
                    item.Click += new RoutedEventHandler(main.undoMenu_Click);
                    main._und开发者_C百科oMenu.Items.Insert(0, item);
                }
            }
            else if (dif < 0)
            {
                for (int i = 0; i < -dif; i++)
                    main._undoMenu.Items.RemoveAt(0);
            }
        }

        if (main.RedoCommands != null)
        {
            dif = main.RedoCommands.Count - main._redoMenu.Items.Count;

            if (dif > 0)
            {
                for (int i = dif - 1; i >= 0; i--)
                {
                    item = new MenuItem();
                    item.Header = main.RedoCommands[i].Name;
                    item.Click += new RoutedEventHandler(main.redoMenu_Click);
                    main._redoMenu.Items.Insert(0, item);
                }
            }
            else if (dif < 0)
            {
                for (int i = 0; i < -dif; i++)
                    main._redoMenu.Items.RemoveAt(0);
            }
        }
    }

XAML:

<r:RibbonGroup GroupSizeDefinitions="{StaticResource RibbonLayoutSmall}">
       <r:RibbonGroup.Command>
              <r:RibbonCommand LabelTitle="Editing"/>
       </r:RibbonGroup.Command>
       <r:RibbonSplitButton Name="_undoMenu" Command="me:AppCommands.Undo" MaxHeight="50"/>
       <r:RibbonSplitButton Name="_redoMenu" Command="me:AppCommands.Redo" MaxHeight="50"/>
</r:RibbonGroup>

WPF RibbonControlsLibrary RibbonSplitButton Items issue

WPF RibbonControlsLibrary RibbonSplitButton Items issue

P.S. even if I change the insert at 0 to a Add, so it will add to the last of the collection instead of first, it doesn't seem to make a difference... if anybody can give me some information regarding what's going on and how to work around this, it will be greatly appreciated. Thanks in advance.


I usually use binding in RibbonSplitButton. So didn't see your issue. You may try RibbonGallery in the RibbonSplitButton and see if it works.

Or use binding like this:

RSB.ItemsSource = new Collection<object> { new { Name = "Paste" }, new { Name = "InsertGlyph" } };

<rb:RibbonGroup Header="ABC">
    <rb:RibbonSplitButton x:Name="RSB">
        <rb:RibbonSplitButton.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Name}" />
            </DataTemplate>
        </rb:RibbonSplitButton.ItemTemplate>
    </rb:RibbonSplitButton>
</rb:RibbonGroup>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜