Tree View Command not working on context menu RRS feed

  • Question

  • I am working on a WPF application. It contains a multi select tree view. The tree is supposed to have different context menu items for each node(i.e at each level of the tree). I am able to populate the tree and even get the context menu to have different options based on the type of data in the tree view. Once i have done this, the command bindings to the context menu items has stopped working. i get an error in the output window as below:

    System.Windows.Data Error: 40 : BindingExpression path error: 'RefreshEvent' property not found on 'object' ''RootNameList' (HashCode=49313939)'. BindingExpression:Path=RefreshEvent; DataItem='RootNameList' (HashCode=49313939); target element is 'MenuItem' (Name=''); target property is 'Command' (type 'ICommand')

    As it is visible in the error, the DataItem is not pointing to the intended ViewModel. Can anyone help me to resolve this issue.

    The code is below:

    <multiselect:MultiSelectTreeView ItemsSource="{Binding TreeViewDataCollection}">
                            <Style x:Key="ExpandingImageStyle" TargetType="{x:Type Image}">
                                <Setter Property="Source" Value="{DynamicResource Icon_Closed}"/>
                                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=multiselect:MultiSelectTreeViewItem}, Path=IsExpanded}" Value="True">
                                        <Setter Property="Source" Value="{DynamicResource Icon_Open}"/>
                            <ContextMenu x:Key="RootMenu">
                                <MenuItem Command="{Binding RefreshEvent}" Header="Refresh">
                                        <Image Source="../Images/Icons/reboot.ico"/>
                            <ContextMenu x:Key="ChildMenu" >
                                <MenuItem Header="Get Configuration" Command="{Binding GetConfigurationEvent}">
                                        <Image Source="../Images/Icons/download.ico"/>
                                <MenuItem Header="Put Configuration" Command="{Binding PutConfigurationEvent}">
                                        <Image Source="../Images/Icons/upload.ico"/>
                            <converter:ContextMenuConverter x:Key="ContextMenuConverter" 
                                                RootMenu="{StaticResource RootMenu}"
                                                ChildMenu="{StaticResource ChildMenu}"/>
                            <Style TargetType="{x:Type multiselect:MultiSelectTreeViewItem}">
                                <Setter Property="ContextMenu" Value="{Binding Converter={StaticResource ContextMenuConverter}}"/>
                            <HierarchicalDataTemplate ItemsSource="{Binding HostGroupName}" DataType="{x:Type mod:RootNameList}">
                                <StackPanel Orientation="Horizontal">
                                    <Image Height="18" Width="18" Source="../Images/Icons/root_subnet.ico"/>
                                    <Label Style="{StaticResource HighlightingTextStyle}" Content="{Binding RootSubnet}"/>
                                    <HierarchicalDataTemplate ItemsSource="{Binding Host}" DataType="{x:Type mod:HostGroup}">
                                        <StackPanel Orientation="Horizontal">
                                            <Image Style="{StaticResource ExpandingImageStyle}" Width="18" Height="18">
                                                    <BitmapImage x:Key="Icon_Closed" UriSource="../Images/Icons/folder_closed.png"/>
                                                    <BitmapImage x:Key="Icon_Open" UriSource="../Images/Icons/folder_opened.png"/>
                                            <Label Style="{StaticResource HighlightingTextStyle}" Content="{Binding GroupName}"/>
                                            <DataTemplate DataType="{x:Type mod:HostName}">
                                                <StackPanel Orientation="Horizontal">
                                                    <Label Style="{StaticResource HighlightingTextStyle}" Content="{Binding Host}"/>
                                                    <Image Source="../Images/Icons/statusnone.ico"/>

    • Edited by Abijithg92 Friday, April 24, 2020 7:37 PM
    • Moved by CoolDadTx Monday, April 27, 2020 1:09 PM WPF related
    Friday, April 24, 2020 2:50 PM

All replies

  • Hi Abijithg92,

    Thank you for posting here.

    Please check if this link below is helpful to you.

    WPF Error 40 BindingExpression path error: property not found on 'object'

    By the way, you can ask questions about wpf in Microsoft Q&A, they are more familiar with it.

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, April 27, 2020 1:35 AM