• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 792
  • Last Modified:

how to create event handler for dynamic menu in WPF


  I am beginner to WPF. I create the menu from database tables using following code....
Now i have struck in, how to call corresponding windows when clicking menu items?
Please its urgent one... help

    <DataTemplate x:Key="navigatetemplate" >
      <TextBlock Text="{Binding menu_name}" ></TextBlock>
    <HierarchicalDataTemplate x:Key="navmenutemplate" 
       ItemsSource="{Binding ChildRelationship}" 
         ItemTemplate="{StaticResource navigatetemplate}">
      <TextBlock Text="{Binding menu_name}"  Name="txtmenu"> </TextBlock>

    <Menu  Name="mymenu" ItemsSource="{Binding dtnavigate}" 
        ItemTemplate="{StaticResource navmenutemplate}"  >
  private void Window_Loaded(object sender, RoutedEventArgs e)
      mymenu.DataContext = getmenu();
    private DataSet getmenu()
      SqlConnection NwindCon = new SqlConnection("server=(local);uid=sa;pwd=zillion;database=ecdslabc20102011");
      SqlDataAdapter navigate = new SqlDataAdapter("select * from navigate order by code ", NwindCon);
      String lc_query = "select n1.code,m.menu_name,m.program from navmenu n1 inner join menu m on n1.menu_code= m.menu_code order by code";
      SqlDataAdapter navmenu = new SqlDataAdapter(lc_query, NwindCon);
      DataSet menudata = new DataSet();
      navigate.Fill(menudata, "dtnavigate");
      navmenu.Fill(menudata, "dtnavmenu");
      DataRelation menurel = new DataRelation("ChildRelationship", menudata.Tables["dtnavigate"].Columns["code"],
         menudata.Tables["dtnavmenu"].Columns["code"], true);
      menurel.Nested = true;
       return menudata;

Open in new window

  • 2
  • 2
1 Solution
zillion_kameshAuthor Commented:
   ur samples all menu are static.. i created menu based on database values.. then where to put eventhandler?
zillion_kameshAuthor Commented:
Thanks for ur solution..  
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now