Issue with checking the menuitem

4 posts, 0 answers
  1. Kiran Ghanwat
    Kiran Ghanwat avatar
    38 posts
    Member since:
    Nov 2009

    Posted 16 Jul 2010 Link to this post

    Hello Community,

        I was using static binding for Menu, IsCheckable property was working fine.
    but, after that when I am using Dynamic binding for menu, IsCheckable property in not working now.

    I am refering this link:
    http://www.telerik.com/help/silverlight/radmenu-populating-with-data-binding-to-dynamic-data.html

    I have changed some code for my purpose

    public ObservableCollection<MenuItem> GetMenuItems(string strChart, List<List<ForecastRatiosChartData>> lstchart, int tag)
    {
    ObservableCollection<MenuItem> IncomeStmtSubItems = new ObservableCollection<MenuItem>();     
    ObservableCollection<MenuItem> ChartSubItems = new ObservableCollection<MenuItem>();
         
    MenuItem newItem;
      
    if (lstchart != null  
      
    for (int rowcnt = 0; rowcnt < lstchart.Count; rowcnt++)
    {
    if (lstchart[rowcnt].ToList().Count > 1)
    {
    newItem = new MenuItem();   
    newItem.Text = lstchart[rowcnt][0].description.Trim();    
    newItem.Tag = tag;   
    newItem.IsCheckable = true  
    newItem.StaysOpenOnClick = true  
    IncomeStmtSubItems.Add(newItem);   
    }
    }
    }
       
    MenuItem Incomestmt = new MenuItem()
     {
      SubItems = IncomeStmtSubItems,
      Text = "Income Statement",
      Tag=0,
      IsCheckable = true,
      StaysOpenOnClick = true,
     };
      
    ChartSubItems.Add(Incomestmt);

        
        
    public class MenuItem 
          
            public MenuItem() 
            
                this.SubItems = new ObservableCollection<MenuItem>(); 
            
        
            public string Text 
            
                get
                set
            
        
            public int Tag 
            
                get
                set
            
        
            public bool IsCheckable 
            
                get
                set
            
        
            public bool StaysOpenOnClick 
            
                get
                set
            
        
            public Uri IconUrl 
            
                get
                set
            
              
            public Image Icon 
            
                get
                
                    return new Image() 
                    
                        Source = new BitmapImage(this.IconUrl) 
                    }; 
                
            
        
            public ObservableCollection<MenuItem> SubItems 
            
                get
                set
            
        }


    Please Help.

    Thanks in advance.
    Kiran Ghanwat
  2. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 16 Jul 2010 Link to this post

    Hello Kiran,

    Thank you for contacting us.

    Could you please send us a sample project illustrating the issue. In that way we will be able to track down the source of the problem in a timely manner.

    Looking forward to your reply.

    Greetings,
    Konstantina
    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 banner
  4. Kiran Ghanwat
    Kiran Ghanwat avatar
    38 posts
    Member since:
    Nov 2009

    Posted 19 Jul 2010 Link to this post

    Hello Konstantina,
     
    I have attached sample code with this reply.
    Tag and IsCheckable properties doesn't get bind to the item.

    Please have a look.

    <UserControl x:Class="SampleMenu.MainPage"
        mc:Ignorable="d"
                  xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"     
        xmlns:telerikNavigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"   
        d:DesignHeight="300" d:DesignWidth="400">
      
        <UserControl.Resources>
            <telerik:HierarchicalDataTemplate x:Key="MenuItemTemplate"
                                     ItemsSource="{Binding SubItems}">
                <TextBlock Text="{Binding Text}" />
            </telerik:HierarchicalDataTemplate>
        </UserControl.Resources>
          
        <Grid x:Name="LayoutRoot" Background="White">
            <telerikNavigation:RadMenu x:Name="radMenu1" Grid.Row="0" Grid.Column="1"
                              ItemTemplate="{StaticResource MenuItemTemplate}">
            </telerikNavigation:RadMenu>
        </Grid>
    </UserControl>


    using System;
    using System.Collections.ObjectModel;
    using System.Windows.Controls;
    using System.Windows.Media.Imaging;
      
    namespace SampleMenu
    {
        public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
                this.radMenu1.ItemsSource = this.GetMenuItems();
            }
      
            public ObservableCollection<MenuItem> GetMenuItems()
            {
                ObservableCollection<MenuItem> item = new ObservableCollection<MenuItem>();
                ObservableCollection<MenuItem> ChartSubItems = new ObservableCollection<MenuItem>();
                 
                MenuItem Incomestmt = new MenuItem()
                {                
                    Text = "Income Statement",
                    Tag = 0,
                    IsCheckable = true,
                    StaysOpenOnClick = true,
                };
                ChartSubItems.Add(Incomestmt);
      
                MenuItem BalanceSheet = new MenuItem()
                {             
                    Text = "Balance Sheet",
                    Tag = 0,
                    IsCheckable = true,
                    StaysOpenOnClick = true
                };
                ChartSubItems.Add(BalanceSheet);
      
                MenuItem CashFlow = new MenuItem()
                {
                    Text = "Cash Flow",
                    Tag = 0,
                    IsCheckable = true,
                    StaysOpenOnClick = true
                };
                ChartSubItems.Add(CashFlow);
      
                MenuItem Ratio = new MenuItem()
                {
                    Text = "Ratio",
                    Tag = 0,
                    IsCheckable = true,
                    StaysOpenOnClick = true
                };
                ChartSubItems.Add(Ratio);
      
                MenuItem Chart = new MenuItem()
                {
                    SubItems = ChartSubItems,
                    Text = "Select Chart",
                    IsCheckable = true,
                    StaysOpenOnClick = true
                };
                item.Add(Chart);
                return item;
            }
        }
      
        public class MenuItem
        {
            public MenuItem()
            {
                this.SubItems = new ObservableCollection<MenuItem>();
            }
      
            public string Text
            {
                get;
                set;
            }
      
            public int Tag
            {
                get;
                set;
            }
      
            public bool IsCheckable
            {
                get;
                set;
            }
      
            public bool StaysOpenOnClick
            {
                get;
                set;
            }
      
            public Uri IconUrl
            {
                get;
                set;
            }
      
            public Image Icon
            {
                get
                {
                    return new Image()
                    {
                        Source = new BitmapImage(this.IconUrl)
                    };
                }
            }
      
            public ObservableCollection<MenuItem> SubItems
            {
                get;
                set;
            }
        }
    }


    Thanks,
    Kiran Ghanwat
  5. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 19 Jul 2010 Link to this post

    Hello Kiran,

    In the following example source code:
    http://demos.telerik.com/silverlight/#Menu/CheckableMenuItems

    There is a attached property, set on the HierarchicalDataTemplate:

    <telerik:ContainerBindingCollection x:Key="DataItemBindings">
     <telerik:ContainerBinding PropertyName="IsSeparator" Binding="{Binding IsSeparator}" />
     <telerik:ContainerBinding PropertyName="IsChecked"
      Binding="{Binding IsChecked, Mode=TwoWay}" />
     <telerik:ContainerBinding PropertyName="IsCheckable" Binding="{Binding IsCheckable}" />
     <telerik:ContainerBinding PropertyName="StaysOpenOnClick"
      Binding="{Binding IsCheckable}" />
    </telerik:ContainerBindingCollection>

    <telerik:HierarchicalDataTemplate x:Key="MenuItemTemplate"
     telerik:ContainerBinding.ContainerBindings="{StaticResource DataItemBindings}"
     ItemsSource="{Binding Items}">
     <TextBlock Text="{Binding Text}" />
    </telerik:HierarchicalDataTemplate>


    It is what's missing from your sample, and I think that if you add it, the problem will disappear. You can find more information about the container bindings here:
    http://www.telerik.com/help/silverlight/radmenu-how-to-group-checkable-menu-items-into-radio-group.html

    Kind regards,
    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
Back to Top