RadMenu SubItems not showing via Binding

4 posts, 0 answers
  1. Brett Pierce
    Brett Pierce avatar
    5 posts
    Member since:
    Feb 2010

    Posted 16 Feb 2010 Link to this post

    I am trying to create a RadMenu by binding, but the top level items show and not the sub items. Am I missing something here?

                            <telerikNavigation:RadMenu ItemsSource="{Binding MenuItems}"  
                                    <telerik:HierarchicalDataTemplate ItemsSource="{Binding Items}" > 
                                        <TextBlock Text="{Binding Name}" /> 

        public class MenuItem 
            public string Name { getset; } 
            public List<MenuItem> Items { getprivate set; } 
            public MenuItem() 
                this.Items = new List<MenuItem>(); 
  2. Valeri Hristov
    Valeri Hristov avatar
    2252 posts

    Posted 16 Feb 2010 Link to this post

    Hi Brett,

    The code looks well. Do you create the menu structure before the binding, or the Items collections are filled after the page is loaded (for example after a response from a web service)? Since you are using simple List<MenuItem>, RadMenu will not receive notifications if it changes after the control is data-bound for the first time. I would recommend trying to change the List<MenuItem> with ObservableCollection<MenuItem>. You could also check our online examples, that demonstrate the same technique:

    If this does not help I would need a simple project that could be used to observe the problem.

    All the best,
    Valeri Hristov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. DevCraft R3 2016 release webinar banner
  4. saw
    saw avatar
    29 posts
    Member since:
    Jun 2014

    Posted 07 Aug 2014 Link to this post

    In my ItemSource i have an id, when user click the text block i want to get particular id related to that text block (clicked text block), in my button click event.

    <TextBlock x:Name="txtTagName" Text="{Binding TagName}"  MouseLeftButtonDown="txtTagName_MouseLeftButtonDown">

    my button click event,
    private void txtTagName_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
                PlannerTagSerializable ob = (PlannerTagSerializable)sender;
    PlannerTagSerializable  is my class that contain Pk_TagId.
    Please help.
  5. Kalin
    Kalin avatar
    1190 posts

    Posted 11 Aug 2014 Link to this post

    Hello Saw,

    Can share some more details - how do you use the mentioned ItemsSource? However I assume you might need to reach the DataContext of the TextBlock. The sender in the MouseLeftButtonDown event handler there would be the TextBlock, so you might need to check in the TextBlock DataContext as shown below:

    private void txtTagName_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        var txtBlock = sender as TextBlock;
        var vm = txtBlock.DataContext as ViewModel; // this is the ViewModel class name
        // PlannerTagSerializable ob = (PlannerTagSerializable)sender;
        // vm.SaveTagforContact(ob.Pk_TagId);  

    Hope this helps.

    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
Back to Top