Binding to context menu

8 posts, 0 answers
  1. ruty
    ruty avatar
    42 posts
    Member since:
    Mar 2009

    Posted 10 Jun 2009 Link to this post

    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.
  2. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 10 Jun 2009 Link to this post

    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.
  3. DevCraft banner
  4. ruty
    ruty avatar
    42 posts
    Member since:
    Mar 2009

    Posted 11 Jun 2009 Link to this post

    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.
  5. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 11 Jun 2009 Link to this post

    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.
  6. ruty
    ruty avatar
    42 posts
    Member since:
    Mar 2009

    Posted 11 Jun 2009 Link to this post

    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,

     
  7. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 11 Jun 2009 Link to this post

    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.
  8. ruty
    ruty avatar
    42 posts
    Member since:
    Mar 2009

    Posted 11 Jun 2009 Link to this post

    I try it,
    This is not set binding to the context menu!!!!!!!!!!!
    :(
    you have more idea for me??
  9. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 11 Jun 2009 Link to this post

    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.
Back to Top
DevCraft banner