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

Binding to context menu

7 Answers 124 Views
Menu
This is a migrated thread and some comments may be shown as answers.
ruty
Top achievements
Rank 1
ruty asked on 10 Jun 2009, 11:59 AM
Hello,
I have application from yours(from last post).
and I want to transfer  the radContextMenu definition from the XAML filt to the CS file:

in the XAML:
<telerikNav:RadContextMenu.ContextMenu> 
 
<telerikNav:RadContextMenu x:Name="ContextMenu" ItemClick="ContextMenu_ItemClick" 
 
ItemsSource="{Binding Items, Source={StaticResource MenuModel}}" 
 
ItemTemplateSelector="{StaticResource ItemTemplateSelector}" /> 
 
</telerikNav:RadContextMenu.ContextMenu> 
 
 and I write in the CS file:
            RadContextMenu ContextMenu = new RadContextMenu();  
            ContextMenu.ItemClick+=new RadRoutedEventHandler(ContextMenu_ItemClick);  
            MenuModel menu = new MenuModel();  
            MenuItemCollection y=  menu.Items;  
            Binding bin = new Binding("Items");  
            bin.Source = y;  
            ContextMenu.SetBinding(RadContextMenu.ItemsSourceProperty,bin); 
but the context menu don't show!!!
Can you help me???
Thanks.

7 Answers, 1 is accepted

Sort by
0
Valeri Hristov
Telerik team
answered on 10 Jun 2009, 01:38 PM
Hi ruty,

You need to set the RadContextMenu.ContextMenu attached property:
DependencyObject elementWithContextMenu = ...;
...

RadContextMenu ContextMenu = new RadContextMenu();
ContextMenu.ItemClick+=new RadRoutedEventHandler(ContextMenu_ItemClick);
MenuModel menu = new MenuModel();
MenuItemCollection y= menu.Items;
Binding bin = new Binding("Items");
bin.Source = y;
ContextMenu.SetBinding(RadContextMenu.ItemsSourceProperty,bin);

elementWithContextMenu.SetValue(RadContextMenu.ContextMenu, ContextMenu);

All the best,
Valeri Hristov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
ruty
Top achievements
Rank 1
answered on 11 Jun 2009, 08:21 AM
Thanks,
But I don't understand Why the intention in the line:
DependencyObject elementWithContextMenu = ...;
...
What needs to define there??
Can you give me a example???
Thanks.
0
Valeri Hristov
Telerik team
answered on 11 Jun 2009, 08:42 AM
Hi ruty,

To use the context menu you need to assign it to an element. When this element is clicked, the context menu will open. For example the following code:

<Rectangle x:Name="rect1">
    <telerikNavigation.RadContextMenu.ContextMenu>
        <telerikNavigation.RadContextMenu ... >
    </telerikNavigation.RadContextMenu.ContextMenu>
</Rectangle>

is equivalent to:

RadContextMenu contextMenu = new RadContextMenu();
...
rect1.SetValue(RadContextMenu.ContextMenu, contextMenu);

Kind regards,
Valeri Hristov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
ruty
Top achievements
Rank 1
answered on 11 Jun 2009, 08:48 AM
Thanks,
 I  assign the context menu to an element (button) thus :
            ContextMenu = new RadContextMenu();  
            ContextMenu.ItemClick+=new RadRoutedEventHandler(ContextMenu_ItemClick);  
            MenuModel menu = new MenuModel();  
            MenuItemCollection y=  menu.Items;  
            Binding bin = new Binding("Items");  
            bin.Source = y;  
            ContextMenu.SetBinding(RadContextMenu.ItemsSourceProperty,bin);  
            but.SetValue(RadContextMenu.ContextMenuProperty, ContextMenu);  
            
The context menu open empty , ( the binding does not  happen.) and in "menu" object have items.(I exam it in debug).
Why???
Thanks,

 
0
Valeri Hristov
Telerik team
answered on 11 Jun 2009, 09:07 AM
Hi ruty,

can you try with:
ContextMenu = new RadContextMenu();
ContextMenu.ItemClick+=new RadRoutedEventHandler(ContextMenu_ItemClick);
// MenuModel menu = new MenuModel();
// MenuItemCollection y= menu.Items;
// Binding bin = new Binding("Items");
// bin.Source = y;
// ContextMenu..SetBinding(RadContextMenu.ItemsSourceProperty,bin);
ContextMenu.ItemsSource = model.Items;
but.SetValue(RadContextMenu.ContextMenuProperty, ContextMenu);



All the best,
Valeri Hristov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
ruty
Top achievements
Rank 1
answered on 11 Jun 2009, 09:21 AM
I try it,
This is not set binding to the context menu!!!!!!!!!!!
:(
you have more idea for me??
0
Valeri Hristov
Telerik team
answered on 11 Jun 2009, 10:23 AM
Hello ruty,

Please, send me your project and I will try to fix it for you. To do that you will have to open a new support ticket and attach the file there.

Greetings,
Valeri Hristov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Menu
Asked by
ruty
Top achievements
Rank 1
Answers by
Valeri Hristov
Telerik team
ruty
Top achievements
Rank 1
Share this question
or