Bind to RadMenuItem Visibility property

7 posts, 0 answers
  1. Wit
    Wit avatar
    1 posts
    Member since:
    Jun 2008

    Posted 18 Jul 2008 Link to this post

    Hi,

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

    Any suggestion?

    Regards,

    Wit

  2. Peter
    Peter avatar
    5 posts
    Member since:
    May 2008

    Posted 18 Jul 2008 Link to this post

    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
  3. DevCraft banner
  4. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 18 Jul 2008 Link to this post

    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
  5. Valio
    Valio avatar
    102 posts
    Member since:
    Jun 2006

    Posted 19 Jul 2008 Link to this post

    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
  6. Peter
    Peter avatar
    5 posts
    Member since:
    May 2008

    Posted 21 Jul 2008 Link to this post

    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
  7. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 21 Jul 2008 Link to this post

    Hi Peter,

    This is the code that populates the menu ItemsSource:

    1     public class League  
    2     {  
    3         public League(string name)  
    4         {  
    5             _name = name;  
    6             _divisions = new List<Division>();  
    7         }  
    8  
    9  
    10         string _name;  
    11  
    12         public string Name { get { return _name; } }  
    13  
    14         List<Division> _divisions;  
    15         public List<Division> Divisions { get { return _divisions; } }  
    16  
    17     }  
    18  
    19     public class Division  
    20     {  
    21         public Division(string name)  
    22         {  
    23             _name = name;  
    24             _teams = new List<Team>();  
    25  
    26         }  
    27  
    28         string _name;  
    29  
    30         public string Name { get { return _name; } }  
    31  
    32         List<Team> _teams;  
    33  
    34         public List<Team> Teams { get { return _teams; } }  
    35  
    36     }  
    37  
    38     public class Team  
    39     {  
    40         public Team(string name)  
    41         {  
    42             _name = name;  
    43         }  
    44  
    45         string _name;  
    46  
    47         public string Name { get { return _name; } }  
    48     }  
    49  
    50     public class LeaguesDataSource : List<League>  
    51     {  
    52         public LeaguesDataSource()  
    53         {  
    54             League l;  
    55             Division d;  
    56  
    57             Add(l = new League("League A"));  
    58             l.Divisions.Add((d = new Division("Division A")));  
    59             d.Teams.Add(new Team("Team I"));  
    60             d.Teams.Add(new Team("Team II"));  
    61             d.Teams.Add(new Team("Team III"));  
    62             d.Teams.Add(new Team("Team IV"));  
    63             d.Teams.Add(new Team("Team V"));  
    64             l.Divisions.Add((d = new Division("Division B")));  
    65             d.Teams.Add(new Team("Team Blue"));  
    66             d.Teams.Add(new Team("Team Red"));  
    67             d.Teams.Add(new Team("Team Yellow"));  
    68             d.Teams.Add(new Team("Team Green"));  
    69             d.Teams.Add(new Team("Team Orange"));  
    70             l.Divisions.Add((d = new Division("Division C")));  
    71             d.Teams.Add(new Team("Team East"));  
    72             d.Teams.Add(new Team("Team West"));  
    73             d.Teams.Add(new Team("Team North"));  
    74             d.Teams.Add(new Team("Team South"));  
    75             Add(l = new League("League B"));  
    76             l.Divisions.Add((d = new Division("Division A")));  
    77             d.Teams.Add(new Team("Team 1"));  
    78             d.Teams.Add(new Team("Team 2"));  
    79             d.Teams.Add(new Team("Team 3"));  
    80             d.Teams.Add(new Team("Team 4"));  
    81             d.Teams.Add(new Team("Team 5"));  
    82             l.Divisions.Add((d = new Division("Division B")));  
    83             d.Teams.Add(new Team("Team Diamond"));  
    84             d.Teams.Add(new Team("Team Heart"));  
    85             d.Teams.Add(new Team("Team Club"));  
    86             d.Teams.Add(new Team("Team Spade"));  
    87             l.Divisions.Add((d = new Division("Division C")));  
    88             d.Teams.Add(new Team("Team Alpha"));  
    89             d.Teams.Add(new Team("Team Beta"));  
    90             d.Teams.Add(new Team("Team Gamma"));  
    91             d.Teams.Add(new Team("Team Delta"));  
    92             d.Teams.Add(new Team("Team Epsilon"));  
    93         }  
    94     } 


    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
  8. Peter
    Peter avatar
    5 posts
    Member since:
    May 2008

    Posted 23 Jul 2008 Link to this post

    thank you -- that did it!
Back to Top
DevCraft banner