Latest News

  • Silverlight Online Chat
    Jul 24, 2010

    Today we launch the new Silverlight Live Chat application demonstrating the Liquid RichTextBox and Emoticon replacements.

  • New Super Shoot Em Up 2 Game
    Jun 29, 2010

    Added to the Games section is the new Super Shoot 'Em Up 2 game. Take control of your tank with the aim to defeat the computer controlled opponents. Features all new weapons, levels and Battle Mode!

  • Silverlight 4 Controls V5.3.2 Released
    Jun 28, 2010

    This release contains several fixes raised in the forums.

  • New Sandmania Puzzle Game
    Jun 18, 2010

    Sandmania is the latest game from vectorlight, the aim of this game is to guide sand from the top of the screen to the various colored containers below.

  • New Moon Tower Defense Game
    May 29, 2010

    Added to the Games section is the new Moon Tower Defense game. Defend the Moon from the circling Aliens and Humans.

johnwyatt
johnwyatt
Creating Main Menu dynamically through code Posted: Oct 15, 2009
 

I am trying to use the MainMenu control dynamically from a database and therefore trying to generate the entire menu from c# code.  I am trying to get the "sub" (second level) menu items to append to the MainMenuItem but I'm missing something.


Here is what I have so far and FYI the Main Menu Items do appear correctly.


        private void ws_GetMainMenuCompleted(object sender, GetMainMenuCompletedEventArgs e)

        {

            if (e.Result != null)

            {

                int i = 0;

                while (i <= e.Result.Count - 1)

                {

                    MainMenuItem mainMenuItem = new MainMenuItem();


                    mainMenuItem.VerticalAlignment = VerticalAlignment.Center;

                    mainMenuItem.HorizontalAlignment = HorizontalAlignment.Center;

                    mainMenuItem.IconColumnWidth = 0;

                    mainMenuItem.ID = e.Result[i].MenuID.ToString();

                    mainMenuItem.Text = e.Result[i].MenuName;

                    mainMenuItem.Tag = e.Result[i].UserControl;

                    mainMenuItem.Background = new SolidColorBrush(Colors.Transparent);

                    mainMenuItem.Foreground = new SolidColorBrush(Colors.White);

                    int x = 0;

                    if (e.Result[i].childItems != null)

                    {

                        if (e.Result[i].childItems.Count > 0)

                        {

                            while (x <= e.Result[i].childItems.Count - 1)

                            {

                                

                                MenuItem subMenuItem = new MenuItem();

                                ItemsControl thisParent = ItemsControl.ItemsControlFromItemContainer(mainMenu);

                                subMenuItem.VerticalAlignment = VerticalAlignment.Top;

                                subMenuItem.HorizontalAlignment = HorizontalAlignment.Center;

                                subMenuItem.IconColumnWidth = 0;

                                subMenuItem.ID = e.Result[i].childItems[x].MenuID.ToString();

                                subMenuItem.Text = e.Result[i].childItems[x].MenuName.ToString();

                                subMenuItem.Tag = e.Result[i].childItems[x].UserControl.ToString();


                                //Need to add subMenuItem to mainMenuItem here


                                x++;

                            }

                        }

                    }

                    mainMenu.Items.Add(mainMenuItem);

                    i++;

                }  

            }

        }


Any help is appreciated.


Thanks

 
 
dan
dan
RE: Creating Main Menu dynamically through code Posted: Oct 15, 2009
 

Hi,


Yes, when you have created the sub menu you need to assign this to the Content property of the MainMenuItem like this:


mainMenuItem.Content = subMenuItem;


I would place this where you currently have your comment:


//Need to add subMenuItem to mainMenuItem here


Thanks!

 
 
johnwyatt
johnwyatt
RE: Creating Main Menu dynamically through code Posted: Nov 03, 2009
 

Thank you for the quick reply it got me going down the right path.  One interesting thing that I found is my subMenuItem had to be casted as a MenuItem in order to be added as Content to my mainMenuItem otherwise I was getting an exception error, but with that changed it works great.


Here's its' current state.


private void ws_GetMainMenuCompleted(object sender, GetMainMenuCompletedEventArgs e)

        {

            if (e.Result == null)

            {

                Common.PopupMessage("Not Authenticated. Please close and reopen your browser.");

            }

            else

            {

                mainMenu.Width = ContentGrid.ActualWidth;

                mainMenu.HorizontalAlignment = HorizontalAlignment.Center;

                mainMenu.VerticalAlignment = VerticalAlignment.Center;

                mainMenu.HorizontalContentAlignment = HorizontalAlignment.Center;

                mainMenu.VerticalContentAlignment = VerticalAlignment.Center;

                int i = 0;

                while (i <= e.Result.Count - 1)

                {

                    MainMenuItem mainMenuItem = new MainMenuItem();

                    mainMenuItem.ID = e.Result[i].MenuID.ToString();

                    mainMenuItem.Text = e.Result[i].MenuName;

                    mainMenuItem.Tag = e.Result[i].UserControl;

                    mainMenuItem.Background = new SolidColorBrush(Colors.Transparent);

                    mainMenuItem.Foreground = new SolidColorBrush(Colors.White);

                    if (e.Result[i].childItems.Count > 0)

                    {

                        Menu subMenu = new Menu();

                        int x = 0;

                        while (x <= e.Result[i].childItems.Count - 1)

                        {

                            MenuItem subMenuItem = new MenuItem();

                            subMenuItem.ID = e.Result[i].childItems[x].MenuID.ToString();

                            subMenuItem.Text = e.Result[i].childItems[x].MenuName.ToString();

                            subMenuItem.Tag = e.Result[i].childItems[x].UserControl.ToString();

                            subMenu.Items.Add(subMenuItem);

                            x++;

                        }

                        mainMenuItem.Content = subMenu;

                    }

                    else

                        mainMenuItem.MouseLeftButtonDown += new MouseButtonEventHandler(mainMenuItem_MouseLeftButtonDown);

                    mainMenu.Items.Add(mainMenuItem);

                    i++;

                }

            }

        }

 
 
johnwyatt
johnwyatt
RE: Creating Main Menu dynamically through code Posted: Nov 03, 2009
 

No Editing features.


I meant to say is my subMenuItem had to be added to a new instance of a Menu in order to be added as Content to my mainMenuItem.


instead of


"One interesting thing that I found is my subMenuItem had to be casted as a MenuItem in order to be added as Content to my mainMenuItem"

 
 
jin.yuan
jin.yuan
RE: Creating Main Menu dynamically through code Posted: Jan 06, 2010
 

Hi, Dan: I have this subMenu working greate. Thanks! But I am having problem to see all items in submenu, since the submenu is close to the bottom of the screen. Is there any way to reposition the submenu or scroll down the submenu items?

Thanks!

 
 
dan
dan
RE: Creating Main Menu dynamically through code Posted: Jan 25, 2010
 

Hi Jin,


Sorry, this is not possible at this time.  It is something we will look into to see how to implement this functionaily in a future version.


Thanks!

 
 

Rate this page: 

1 Star 2 Star 3 Star 4 Star 5 Star
8 Ratings / 2.5 Average