Quantcast
Channel: Problem with MenuItem click
Viewing all articles
Browse latest Browse all 2

Problem with MenuItem click

0
0
Hi ,
Im having following xaml
 <Window.Resources>

        <HierarchicalDataTemplate DataType="Module" ItemsSource="{Binding XPath=*}">
            <!--<MenuItem Header="{Binding XPath=@name}" Height="15" StaysOpenOnClick="True"  />-->
            <TextBlock  
                Text="{Binding XPath=@name}" />
        </HierarchicalDataTemplate>
        <DataTemplate DataType="SubModule" x:Key="TemplateModule"  >
            <MenuItem Header="{Binding XPath=@name}"  Click="MenuItem_Click">

            </MenuItem>
            <!--<TextBlock  
                Text="{Binding XPath=@name}" 
                MouseLeftButtonDown="TextBlock_MouseLeftButtonDown"/>-->
        </DataTemplate>
        <XmlDataProvider x:Key="dataProvider" XPath="MenuItems" Source="Books.xml">

        </XmlDataProvider>

    </Window.Resources>
    <Grid x:Name="MainGridMenuBar"  VerticalAlignment="Top" Background="Transparent">
        <Menu  Name="MainMenubar" ItemsSource="{Binding Source={StaticResource dataProvider}, XPath=Module}" VerticalAlignment="Top" >

        </Menu>
    </Grid>

When i click on Menuitem ,it raise MenuItem_Click event.  Im getting information.For showing clicked element ,I am having following c# code


 private void MenuItem_Click(object sender, RoutedEventArgs e)
        {

            MenuItem  m = e.OriginalSource as MenuItem;
            System.Xml.XmlAttribute att = m.Header as System.Xml.XmlAttribute;
            MessageBox.Show(att.Value);   
            
        }


Is there any other way handling c# code in xaml itself without doing boxing...r do i need to write convertor class and add it to bind property of text?


With regards,
Mahender

Mahender

Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images