Thursday, March 19, 2009

Changing the default Silverlight 3.0 menu to the AgMenu from DevExpress

As you all know, well maybe not all, that the new Silverlight 3.0 offers a new template called Silverlight Navigation Application, now this creates "Views" which are switched to and from using a default menu, and also supports the browser Back and Forward buttons.













But i didn't like the default Button menu provided, so i set out to use the AgMenu from DevExpress.

Now, digging into the Xaml, it's pretty simple, Add your namespace reference in the MainPage.xml file

    4 xmlns:dxm="clr-namespace:DevExpress.AgMenu;assembly=DevExpress.AgMenu.v9.1"


Add your menu xaml and overwrite the default Home & About buttons with

   13  x:Name="rootMenu" Height="28" VerticalAlignment="Top">

   14                         IsCheckable="False" x:Name="mnuUserName" Header="Home" Tag="/Views/HomePage.xaml" Click="mnuItems_Clicked"/>

   15                         IsCheckable="False" x:Name="mnuHome" Header="About" Tag="/Views/AboutPage.xaml" Click="mnuItems_Clicked" />

   16                    


Now all you need todo is wireup your Clicked events for the AgMenuItem's and you are done.

   32         private void mnuItems_Clicked(object sender, EventArgs e)  {

   33             String goToPage = (sender as AgMenuItem).Tag.ToString();

   34             this.Frame.Navigate(new Uri(goToPage, UriKind.Relative));

   35         }


And the finished Product


No comments:

Post a Comment