WPF Pass MenuItem selected as MethodParameter to ObjectDataProvider

Posted by Shravan on Stack Overflow See other posts from Stack Overflow or by Shravan
Published on 2010-03-10T15:51:54Z Indexed on 2010/06/16 18:02 UTC
Read the original article Hit count: 418

Filed under:
|
|

I am trying to pass Selected MenuItem's Text/Header string as the MethodParameter to my ObjectDataProvider. I have seen examples like these on the internet but haven't been able to adapt it to the Menu Control specifically. I am new to WPF and need some help accomplish this. Any help would be greatly appreciated.

Below is the code snippet, XAML for the ObjectDataProvider

<Window.Resources>
    <ObjectDataProvider x:Key="NMInfo" ObjectType="{x:Type local:NMInfoProvider}" MethodName="GetDcmsInfomation" IsAsynchronous="True">
        <ObjectDataProvider.MethodParameters>
            <x:Static Member="system:String.Empty" />
        </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>
</Window.Resources>

XAML for the Menu control

<Menu Name="nmMenu" Height="25" HorizontalAlignment="Stretch" VerticalAlignment="Top" FontSize="12" DockPanel.Dock="Top">

        <Menu.BitmapEffect>
            <DropShadowBitmapEffect/>
        </Menu.BitmapEffect>
        <MenuItem Header="File">

            <MenuItem Header="SNYC12P10650" IsCheckable="True" ToolTip="Production" Click="MenuItem_Clicked">
                <MenuItem.IsChecked>
                    <Binding Source="{StaticResource NMInfo}" Path="MethodParameters[0]" BindsDirectlyToSource="True" Mode="OneWayToSource"/>
                </MenuItem.IsChecked>
            </MenuItem>
            <MenuItem Header="GPRI12D10217" IsCheckable="True" ToolTip="QA" Click="MenuItem_Clicked">
               <MenuItem.IsChecked>
                    <Binding Source="{StaticResource NMInfo}" Path="MethodParameters[0]" BindsDirectlyToSource="True" Mode="OneWayToSource"/>
                </MenuItem.IsChecked>
            </MenuItem>
            <MenuItem Header="GPRI12D10219" IsCheckable="True" ToolTip="Dev" Click="MenuItem_Clicked">
                <MenuItem.IsChecked>
                    <Binding Source="{StaticResource NMInfo}" Path="MethodParameters[0]" BindsDirectlyToSource="True" Mode="OneWayToSource"/>
                </MenuItem.IsChecked>
            </MenuItem>
            <Separator/>
            <MenuItem Header="Close"/>
        </MenuItem>

    </Menu>

© Stack Overflow or respective owner

Related posts about wpf

Related posts about menuitem