Pages

Wednesday, 9 February 2011

dynamically create an agmenus in silverlight

foreach (var row in menulists)
            {
                 if(row.Pid==null || row.Pid==0)
                {
                    parentItem = new AgMenuItem();
                    parentItem.Header = row.Text;
                    parentItem.Tag = row.Url;
                    parentItem.Click += new EventHandler(parentItem_Click);
                    SPMenus.Items.Add(parentItem);

                }
                else
                {
                    DevExpress.AgMenu.AgMenuItem objSubitem = new AgMenuItem();
                    objSubitem.Header = row.Text;
                    objSubitem.Tag = row.Url;
                    objSubitem.Click += new EventHandler(objSubitem_Click);
                    parentItem.Items.Add(objSubitem);
                    objSubitem.Visibility = Visibility.Visible;
                }
            }

 void parentItem_Click(object sender, EventArgs e)
        {
            //var item = sender as DevExpress.AgMenu.AgMenuItem;

            //string str = "http://203.193.129.34/reports";

            //Uri objUri = new Uri(str, UriKind.RelativeOrAbsolute);
            //ContentFrame.Navigate(objUri);

            var item = sender as DevExpress.AgMenu.AgMenuItem;

            SPSubItemsofAgMenus.Children.Clear();

            foreach (DevExpress.AgMenu.AgMenuItem row in item.ParentItem.Items)
            {
                Button button = new Button();
                button.Content = "";
                button.Height = 30;
                button.Content = row.Header;
                button.Tag = row.Tag;
                SPSubItemsofAgMenus.Children.Add(button);
                button.Click += new RoutedEventHandler(button_Click);
            }
        }

No comments:

Post a Comment