WPF RibbonControlsLibrary RibbonSplitButton 项目问题
我正在使用 RibbonSplitButton 及其下拉菜单中的菜单项来模仿 Visual Studio 的撤消重做按钮。 我们有撤消重做堆栈,我有一个 dependencypropertychanged 事件处理程序,它将根据堆栈更新 UI。问题是,分割按钮的 items 属性正在使用 Collection,即使其项目集合的顺序正确,它也不会显示它们,因为它们是按索引排序的。
我将在下面提供一些示例来更好地解释这一点:
代码:
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._undoMenu.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>
PS 即使我将 0 处的插入更改为 Add,因此它将添加到集合的最后一个而不是第一个,它似乎没有什么区别... 如果有人能给我一些有关正在发生的事情以及如何解决此问题的信息,我将不胜感激。 提前致谢。
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._undoMenu.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>
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通常在 RibbonSplitButton 中使用绑定。所以没看到你的问题。您可以在 RibbonSplitButton 中尝试 RibbonGallery 并查看是否有效。
或者使用这样的绑定:
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: