1

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?

karthik
  • 17,453
  • 70
  • 78
  • 122
Ragowit
  • 161
  • 2
  • 8

1 Answers1

1

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);
    }
}
Miklós Balogh
  • 2,164
  • 2
  • 19
  • 26
  • Thank you, this pointed me into the right direction. Your RibbonSelectionChanged event didn't work for me, but inside the RibbonGalleryItem (after ItemsSource) so did I add the ribbon:RibbonGalleryItem.Selected="RibbonGalleryItem_Selected"-event, and that worked just like I wanted it to. – Ragowit Dec 23 '11 at 09:29