AuxiliaryPaneContent 内 RibbonGalleryCategory 中的单击事件?

发布于 2024-12-22 13:55:18 字数 410 浏览 7 评论 0原文

我一直在遵循本页底部的示例:

http://msdn.microsoft.com/en-us/library/microsoft.windows.controls.ribbon.ribbonapplicationmenu.auxiliarypanecontent.aspx

获取“最新文档”列表。我已填充列表,我可以单击此列表中的项目,但我找不到捕获单击事件的位置。

我需要知道用户何时以及在该列表中单击了哪些项目。

如何?

I have been following the example on the bottom of this page:

http://msdn.microsoft.com/en-us/library/microsoft.windows.controls.ribbon.ribbonapplicationmenu.auxiliarypanecontent.aspx

to get a "Most recent documents" list. I have the list populated and I can click on the items in this list but I can't find where to catch the click event.

I need to know when and on what item the user has clicked on in this list.

How?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

み青杉依旧 2024-12-29 13:55:18

有两种方法可以解决它。

第一:使用 Ribbon.SelectionChanged 事件。它也会捕获您的 ListBox SelectionChanged 事件,您可以向其中添加逻辑。

private void RibbonSelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (e.OriginalSource is Ribbon)
        {
           //implement your logic
        }
        if (e.OriginalSource is ListBox)
        {
            //implement your logic
        }
    }

第二:我更喜欢使用ListView,但我认为在这种情况下它是一样的。使用 Click 事件创建自定义列表框。

public class RecentItemsList : System.Windows.Controls.ListView
{
    public delegate void RecentItemClicked(object param);

    public event RecentItemClicked Click;
    public RecentItemsList()
    {
        SelectionChanged += RecentItemsList_SelectionChanged;
        SetValue(ScrollViewer.HorizontalScrollBarVisibilityProperty, ScrollBarVisibility.Hidden);

        //...

    }

    private void RecentItemsList_SelectionChanged(object sender, SelectionChangedEventArgs selectionChangedEventArgs)
    {
        if (SelectedIndex > -1)
        {
            //...
            OnClick();
        }
    }

    private void OnClick()
    {
        if (Click != null)
            Click(null);
    }
}

There are two ways you can solve it.

First: Use Ribbon.SelectionChanged event. It will catch your ListBox SelectionChanged event too and you can add your logic to it.

private void RibbonSelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (e.OriginalSource is Ribbon)
        {
           //implement your logic
        }
        if (e.OriginalSource is ListBox)
        {
            //implement your logic
        }
    }

Second: I prefer to use ListView but I think its the same in this case. Create your custom ListBox with Click event.

public class RecentItemsList : System.Windows.Controls.ListView
{
    public delegate void RecentItemClicked(object param);

    public event RecentItemClicked Click;
    public RecentItemsList()
    {
        SelectionChanged += RecentItemsList_SelectionChanged;
        SetValue(ScrollViewer.HorizontalScrollBarVisibilityProperty, ScrollBarVisibility.Hidden);

        //...

    }

    private void RecentItemsList_SelectionChanged(object sender, SelectionChangedEventArgs selectionChangedEventArgs)
    {
        if (SelectedIndex > -1)
        {
            //...
            OnClick();
        }
    }

    private void OnClick()
    {
        if (Click != null)
            Click(null);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文