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

DataContext binding ignored

3 Answers 175 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 21 Nov 2012, 04:39 AM
DataConext binding for my RadContextMenu is being ignored. My menu is defined like this:

<UserControl.Resources>
    <telerik:RadContextMenu x:Key="LimbContextMenu" DataContext="{Binding SelectedLimb}" >
        <telerik:RadMenuItem Header="Expand" Command="{Binding ExpandItemCommand}" />
        <telerik:RadMenuItem Header="Expand to book" Command="{Binding ExpandToBookCommand}" />
        <telerik:RadMenuItem Header="Collapse" Command="{Binding CollapseItemCommand}" />
        <telerik:RadMenuItem Header="Collapse all" Command="{Binding CollapseAllCommand}" />
        <telerik:RadMenuItem Header="Jump to home" Command="{Binding JumpToHomeCommand}"
                             Visibility="{Binding JumpToHomeCommand.IsSupported, Converter={StaticResource BooleanToVisibilityConverter}}"/>
    </telerik:RadContextMenu>
</UserControl.Resources>


It works if I define it like this:
<UserControl.Resources>
    <telerik:RadContextMenu x:Key="LimbContextMenu"   >
      <telerik:RadContextMenu DataContext="{Binding SelectedLimb}">
        <telerik:RadMenuItem Header="Expand" Command="{Binding ExpandItemCommand}" />
        <telerik:RadMenuItem Header="Expand to book" Command="{Binding ExpandToBookCommand}" />
        <telerik:RadMenuItem Header="Collapse" Command="{Binding CollapseItemCommand}" />
        <telerik:RadMenuItem Header="Collapse all" Command="{Binding CollapseAllCommand}" />
        <telerik:RadMenuItem Header="Jump to home" Command="{Binding JumpToHomeCommand}"
                             Visibility="{Binding JumpToHomeCommand.IsSupported, Converter={StaticResource BooleanToVisibilityConverter}}"/>
      </telerik:RadContextMenu>
    </telerik:RadContextMenu>
</UserControl.Resources>

But this version displays a menu within a menu.

How can I get DataConext assigned on the outer menu?

3 Answers, 1 is accepted

Sort by
0
Accepted
Rosen Vladimirov
Telerik team
answered on 21 Nov 2012, 03:14 PM
Hi David,

By default RadContextMenu inherits the DataContext of the UIElement on which it is attached. If you want to set DataContext, you have to use InheritDataContext property and set it to false (the default value is true).
<UserControl.Resources>
<telerik:RadContextMenu x:Key="LimbContextMenu" DataContext="{Binding SelectedLimb}" InheritDataContext="False">
...

Don't hesitate to contact us if you have any problems or concerns.

Greetings,
Rosen Vladimirov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
David
Top achievements
Rank 1
answered on 26 Nov 2012, 10:02 PM
Thanks. That worked fine. I like it when the solution is easy!
0
Mahdi
Top achievements
Rank 1
answered on 11 Jun 2014, 08:56 AM
Thanks Rosen Vladimirov. It's easy and practical.
Tags
ContextMenu
Asked by
David
Top achievements
Rank 1
Answers by
Rosen Vladimirov
Telerik team
David
Top achievements
Rank 1
Mahdi
Top achievements
Rank 1
Share this question
or