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

RadMenu SubItems not showing via Binding

3 Answers 170 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Brett Pierce
Top achievements
Rank 1
Brett Pierce asked on 16 Feb 2010, 09:29 AM
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}"  
                                                   VerticalAlignment="Top"  
                                                   > 
                            <telerikNavigation:RadMenu.ItemTemplate> 
                                <telerik:HierarchicalDataTemplate ItemsSource="{Binding Items}" > 
                                    <TextBlock Text="{Binding Name}" /> 
                                </telerik:HierarchicalDataTemplate> 
                            </telerikNavigation:RadMenu.ItemTemplate> 
                        </telerikNavigation:RadMenu> 
 


    public class MenuItem 
    { 
        public string Name { getset; } 
 
        public List<MenuItem> Items { getprivate set; } 
 
        public MenuItem() 
        { 
            this.Items = new List<MenuItem>(); 
        } 
    } 
 

3 Answers, 1 is accepted

Sort by
0
Valeri Hristov
Telerik team
answered on 16 Feb 2010, 10:04 AM
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:
http://demos.telerik.com/silverlight/#Menu/DataBinding

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.
0
saw
Top achievements
Rank 1
answered on 07 Aug 2014, 11:58 AM
Hi,
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;
            vm.SaveTagforContact(ob.Pk_TagId);
            
        }
PlannerTagSerializable  is my class that contain Pk_TagId.
Please help.
0
Kalin
Telerik team
answered on 11 Aug 2014, 01:01 PM
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.

Regards,
Kalin
Telerik
 
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.
 
Tags
Menu
Asked by
Brett Pierce
Top achievements
Rank 1
Answers by
Valeri Hristov
Telerik team
saw
Top achievements
Rank 1
Kalin
Telerik team
Share this question
or