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

Disable non-user context menu

5 Answers 45 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Antoniy
Top achievements
Rank 1
Antoniy asked on 13 Aug 2012, 01:01 PM

I'm using Telerik's context menu and would like to disable Silverlight's default context menu on all items without set menu.

I've tried to handle MouseRightButtonDown on MainPage but events from popups (ComboBoxes' dropdowns, ChildWindows & others) don't go through the tree to the MainPage so they still have that menu.

Is there a way to globally disable the default context menu? As the only way I've come up with is to extend some of the controls and handle the event but still can't figure it out how to deal with ComboBoxes' dropdowns.

5 Answers, 1 is accepted

Sort by
0
Rosen Vladimirov
Telerik team
answered on 14 Aug 2012, 02:14 PM
Hello,

Unfortunately there's no easy way to disable the default context menu. The first step (which I believe you have done by yourself) is to set the event on RightMouseButtonDown for the whole grid as handled:
<Grid x:Name="LayoutRoot" MouseRightButtonDown="LayoutRoot_MouseRightButtonDown" Background="White">
...
</Grid>

private void LayoutRoot_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
    e.Handled = true;
}

After that you'll have to do the same for all popups. For the ComboBox you have to apply this for each ComboBoxItem and for the ComboBox itself:

<telerik:RadComboBox x:Name="comboBox" VerticalAlignment="Center" HorizontalAlignment="Center" MouseRightButtonDown="LayoutRoot_MouseRightButtonDown">
    <telerik:RadComboBoxItem Content="Item 1" IsSelected="True" MouseRightButtonDown="LayoutRoot_MouseRightButtonDown"/>
    <telerik:RadComboBoxItem Content="Item 2" MouseRightButtonDown="LayoutRoot_MouseRightButtonDown"/>
    <telerik:RadComboBoxItem Content="Item 3" MouseRightButtonDown="LayoutRoot_MouseRightButtonDown"/>
</telerik:RadComboBox>

Hopefully this helps! Don't hesitate to contact us if you have any questions or suggestion for RadControls.

Greetings,
Rosen Vladimirov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Antoniy
Top achievements
Rank 1
answered on 20 Aug 2012, 02:05 PM
Hello,

How can I handle the event on the RadWindow's modal background and ComboBox's items' when the control is bound.

Thanks.
0
Rosen Vladimirov
Telerik team
answered on 22 Aug 2012, 05:44 AM
Hello,

For the RadComboBox you may apply an ItemTemplate to all items and include the event handler in it. Here's one possible implementation:
<DataTemplate x:Key="comboBoxItemTemplate">
    <Grid Background="White" MouseRightButtonDown="LayoutRoot_MouseRightButtonDown">
        <ContentPresenter Content="{Binding}"  MouseRightButtonDown="LayoutRoot_MouseRightButtonDown"/>
    </Grid>
</DataTemplate>

And apply it on the RadComboBox this way:
<telerik:RadComboBox x:Name="comboBox"
                ItemTemplate="{StaticResource comboBoxItemTemplate}"
                VerticalAlignment="Center"
                HorizontalAlignment="Center"
                MouseRightButtonDown="LayoutRoot_MouseRightButtonDown">

If you open your RadWindow on ButtonClick you may use the following code to disable the context menu when the ModalBackground is set:
private void Button_Click(object sender, RoutedEventArgs e)
{
    var win = new RadWindow();
    win.ModalBackground = new SolidColorBrush(Colors.Red);
    win.Loaded += new RoutedEventHandler(win_Loaded);
    win.ShowDialog();
}
 
void win_Loaded(object sender, RoutedEventArgs e)
{
    var win = (sender as RadWindow);
    var modalBackground = win.ParentOfType<Canvas>();
    if (modalBackground != null)
        modalBackground.MouseRightButtonDown += new MouseButtonEventHandler(LayoutRoot_MouseRightButtonDown);
 
}

Hopefully these solutions help in your case!

Kind regards,
Rosen Vladimirov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Antoniy
Top achievements
Rank 1
answered on 22 Aug 2012, 01:01 PM
Hello,

Unfortunately RadComboBox's solution doesn't work when using DisplayMemberName.

Is there a way to intercept RadComboBoxItems' creation and wire up the event?

Also I don't want to make any changes to the existing code except changing the control to the extended one.

Thanks.
0
Rosen Vladimirov
Telerik team
answered on 23 Aug 2012, 05:16 PM
Hello,

As you don't want to make changes to the existing code, I would suggest you to modify the ImplicitStyle you are using. This can be done pretty easy by using Blend or with the tool from this blog post.
If you use the tool from the blog please follow the steps below:
1) Start the tool and load the Telerik.Windows.Controls.Input.xaml file from <RadControls Installation Directory>\Thems.Implicit\<Theme you are using>\Themes\
2) From the top-left dropdown button choose Implicit Styles
3) Choose both RadComboBox and RadComboBoxItem styles
4) Copy the code shown on the right side and paste it in your UserControl.Resources (don't forget to remove the <ResourceDictionary> open and closing tags at the beginning and at the end of the generated code.
5) You'll have to add
MouseRightButtonDown="LayoutRoot_MouseRightButtonDown"
on several places depending your needs.

After doing this you won't see the default Silverlight Context Menu on your comboBoxes.
To illustrate it I've made a simple project where you'll find a simple NonEditableRadComboBox - you can check exactly where I have attached the MouseRightButtonDown event.

Hopefully this will fix your problem.

Regards,
Rosen Vladimirov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
General Discussions
Asked by
Antoniy
Top achievements
Rank 1
Answers by
Rosen Vladimirov
Telerik team
Antoniy
Top achievements
Rank 1
Share this question
or