Vectorlight News

  • Chat App Converted to HTML and JQuery
    Sep 08, 2011

    Converted from Silverlight to HTML and Javascript/JQuery is the Vectorlight Chat App. Login using your Vectorlight password to chat using your username and avatar.

  • HTML5 iPhone,Android Big Guns Tower Defense
    Jul 02, 2011

    Big Guns has made the leap from Windows Phone 7 (XNA) to HTML5 so you can now play it on your iPhone, Android and other HTML5 compatible devices.

  • HTML5 Games - Word Poppers and Batty
    Jun 04, 2011

    As the take-up of HTML5 quickens (74% of users currently have a browser capable of HTML5 Canvas) we present two more games for both your browser and mobile.

  • Big Guns Tower Defense on Windows Phone 7
    May 06, 2011

    Coming soon to Windows Phone 7 is an XNA port of the popular Vectorlight tower defense game Super Tower Defense. Whilst retaining many of the graphical and gameplay features of the original Silverlight game.

  • Wakacube WP7 Update
    Apr 26, 2011

    Released to the Windows Phone 7 marketplace today is Version 1.1 of Wakacube the 3D physics game of skill. Included in the update are more levels (30 in total) and new mode Wakatime which generates random crate structures to keep players entertained long after the levels have been completed.

  • Home Page News
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: 

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