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

how to create event handler for dynamic menu in WPF

Hi,

  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


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

  <StackPanel>
    <Menu  Name="mymenu" ItemsSource="{Binding dtnavigate}" 
        ItemTemplate="{StaticResource navmenutemplate}"  >
    </Menu>
  </StackPanel>
  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;
      menudata.Relations.Add(menurel);
       return menudata;
    }

Open in new window

0
zillion_kamesh
Asked:
zillion_kamesh
  • 2
  • 2
1 Solution
 
zillion_kameshAuthor Commented:
Hi,
   ur samples all menu are static.. i created menu based on database values.. then where to put eventhandler?
0
 
CuteBugCommented:
0
 
zillion_kameshAuthor Commented:
Thanks for ur solution..  
0
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