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

Bind to RadMenuItem Visibility property

6 Answers 157 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Wit
Top achievements
Rank 1
Wit asked on 18 Jul 2008, 01:17 PM

Hi,

I try to bind business object to RadMenuItem Visibility property. It doesn’t work.

Any suggestion?

Regards,

Wit

6 Answers, 1 is accepted

Sort by
0
Peter
Top achievements
Rank 1
answered on 18 Jul 2008, 03:02 PM
I have the same problem.  Here is what I'm trying to accomplish, I want to use the menu control but programmically alter the menu options based on condtions.  Meaning user running the menu would have different options from another user -- of course using the same xaml.  The menu control is working fine if its "hard coded", has anyone tried to bind it to an object instead,  Any working code example would be greatly appreciatred.

Thanks
0
Hristo
Telerik team
answered on 18 Jul 2008, 03:12 PM
Hi Wit, Peter,

I am not sure that I understand what you are trying to do. Can someone send me a sample project, or just paste here some code?

Please keep in mind that if you want to bind Visibility to Boolean property you should make a Converter class that implements IValueConverter. Also at the moment Silverlight Beta 2 supports only BindingMode = OneTime for DependencyProperty no matter what you set to Mode property when you create Binding object.

Thank you for the feedback.

Best wishes,
Hristo
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Valio
Top achievements
Rank 1
answered on 19 Jul 2008, 07:09 AM
Hi Peter,

there is a good example for menu binding here:
http://telerik.com/demos/silverlight/#Examples/Menu/DataSource

The menu control is fully functional in data binding scenario.

In your scenario you should bind the Menu to an ObservableCollection , and to modify the collection , which will result in showing/hiding the menu items automaticaly.

Let us know if you need more help on this. 

Best Regards,
Valentin Stoychev
Telerik
0
Peter
Top achievements
Rank 1
answered on 21 Jul 2008, 04:04 PM
Valentin,

Thank you , I'm close -- I see in the example its binding to a collection defined in the static resource file, could you cut and paste the relevant portion of the static resource so I can follow it in its entirety.

Thanks Peter
0
Hristo
Telerik team
answered on 21 Jul 2008, 04:23 PM
Hi Peter,

This is the code that populates the menu ItemsSource:

    public class League  
    {  
        public League(string name)  
        {  
            _name = name;  
            _divisions = new List<Division>();  
        }  
 
 
        string _name;  
 
        public string Name { get { return _name; } }  
 
        List<Division> _divisions;  
        public List<Division> Divisions { get { return _divisions; } }  
 
    }  
 
    public class Division  
    {  
        public Division(string name)  
        {  
            _name = name;  
            _teams = new List<Team>();  
 
        }  
 
        string _name;  
 
        public string Name { get { return _name; } }  
 
        List<Team> _teams;  
 
        public List<Team> Teams { get { return _teams; } }  
 
    }  
 
    public class Team  
    {  
        public Team(string name)  
        {  
            _name = name;  
        }  
 
        string _name;  
 
        public string Name { get { return _name; } }  
    }  
 
    public class LeaguesDataSource : List<League>  
    {  
        public LeaguesDataSource()  
        {  
            League l;  
            Division d;  
 
            Add(l = new League("League A"));  
            l.Divisions.Add((d = new Division("Division A")));  
            d.Teams.Add(new Team("Team I"));  
            d.Teams.Add(new Team("Team II"));  
            d.Teams.Add(new Team("Team III"));  
            d.Teams.Add(new Team("Team IV"));  
            d.Teams.Add(new Team("Team V"));  
            l.Divisions.Add((d = new Division("Division B")));  
            d.Teams.Add(new Team("Team Blue"));  
            d.Teams.Add(new Team("Team Red"));  
            d.Teams.Add(new Team("Team Yellow"));  
            d.Teams.Add(new Team("Team Green"));  
            d.Teams.Add(new Team("Team Orange"));  
            l.Divisions.Add((d = new Division("Division C")));  
            d.Teams.Add(new Team("Team East"));  
            d.Teams.Add(new Team("Team West"));  
            d.Teams.Add(new Team("Team North"));  
            d.Teams.Add(new Team("Team South"));  
            Add(l = new League("League B"));  
            l.Divisions.Add((d = new Division("Division A")));  
            d.Teams.Add(new Team("Team 1"));  
            d.Teams.Add(new Team("Team 2"));  
            d.Teams.Add(new Team("Team 3"));  
            d.Teams.Add(new Team("Team 4"));  
            d.Teams.Add(new Team("Team 5"));  
            l.Divisions.Add((d = new Division("Division B")));  
            d.Teams.Add(new Team("Team Diamond"));  
            d.Teams.Add(new Team("Team Heart"));  
            d.Teams.Add(new Team("Team Club"));  
            d.Teams.Add(new Team("Team Spade"));  
            l.Divisions.Add((d = new Division("Division C")));  
            d.Teams.Add(new Team("Team Alpha"));  
            d.Teams.Add(new Team("Team Beta"));  
            d.Teams.Add(new Team("Team Gamma"));  
            d.Teams.Add(new Team("Team Delta"));  
            d.Teams.Add(new Team("Team Epsilon"));  
        }  
    } 


This is not an Observable collection so changing the collection will not change the MenuItems, but if you change LeaguesDataSource : List<League> to  LeaguesDataSource : ObservableCollection<League> changes from collection will reflect in Menu.

In your case if you want to hide MenuItem you can remove it from the collection.

If you have any other question I'll be glad to help.

Regards,
Hristo
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Peter
Top achievements
Rank 1
answered on 23 Jul 2008, 02:09 PM
thank you -- that did it!
Tags
General Discussions
Asked by
Wit
Top achievements
Rank 1
Answers by
Peter
Top achievements
Rank 1
Hristo
Telerik team
Valio
Top achievements
Rank 1
Share this question
or