This is a migrated thread and some comments may be shown as answers.

Context menu on FilteringControl

3 Answers 128 Views
GridView
This is a migrated thread and some comments may be shown as answers.
nagibator4000
Top achievements
Rank 1
nagibator4000 asked on 26 Jul 2017, 12:34 PM

Hello everyone.

Is it possible to add context menu (RadContextMenu or System.Windows.Controls.ContextMenu) to filtering control in RadGridView?

I need to implement copy and past functions on textboxes in the FilteringControl.

It is the sample where I try to do this ( https://drive.google.com/file/d/0B1j-40J5aVOfSEctRHdZYnh3RjA/view?usp=sharing ). 
There are ContextMenu in UserControlWithMenu and in FilteringControlEx, but both of them doesn't appear on right mouse click.

3 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 31 Jul 2017, 11:04 AM
Hello Egor,

In this particular scenario, the filtering control handles the mouse right-click event and thus, the context menu is not shown, however, you can manually display the menu by defining your custom control like so:

class FilteringControlEx : FilteringControl
{
    public RadContextMenu contextMenu;
 
    public FilteringControlEx(Telerik.Windows.Controls.GridViewColumn column)
        : base(column)
    {
        DefaultStyleKey = typeof(FilteringControlEx);
        this.Loaded += FilteringControlEx_Loaded;
    }
 
    private void FilteringControlEx_Loaded(object sender, RoutedEventArgs e)
    {
        contextMenu = new RadContextMenu();
        contextMenu.Items.Add(new RadMenuItem() { Header = "aaa" });
        this.MouseRightButtonUp += FilteringControlEx_MouseRightButtonDown;
    }
 
    private void FilteringControlEx_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
    {
        contextMenu.PlacementTarget = e.OriginalSource as FrameworkElement;
        contextMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
        contextMenu.IsOpen = true;
    }
 
    protected override void OnMouseUp(MouseButtonEventArgs e)
    {
        base.OnMouseUp(e);
        e.Handled = false;
    }
 
    protected override void OnMouseDown(MouseButtonEventArgs e)
    {
        base.OnMouseDown(e);
        e.Handled = false;
    }
}

Please let me know if this works for you.

Regards,
Dilyan Traykov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
nagibator4000
Top achievements
Rank 1
answered on 02 Aug 2017, 10:19 AM
Hello, Dilyan,

Thank you for the answer. Your solution works. 
I need to close filtering control, when it lose focus. If I set property RadGridView.ShouldCloseFilteringPopupOnKeyboardFocusChanged = true, the filter is closing after menu appears.
I've tried to change the property in FilteringControlEx_MouseRightButtonDown to false and in ContextMenuOnClosed to true back. In this case menu works, but filter doesn't close, when it lose focus.

Is there any way to make it work?
0
Stefan
Telerik team
answered on 07 Aug 2017, 08:52 AM
Hello Egor,

In order to close the filtering control, you need to access its Popup element and set its IsOpen property to false. The approach is demonstrated in the Close Filtering Popup on Pressing Filter Button help article. Can you please check it out?

Regards,
Stefan X1
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
nagibator4000
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
nagibator4000
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or