A
Abijithg92
Guest
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)'. BindingExpressionath=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 x:Name="Root" HorizontalAlignment="Stretch" Margin="0" BorderBrush="Gainsboro" Background="#FFF0EEEE" Width="250" VerticalAlignment="Stretch" ItemsSource="{Binding TreeViewDataCollection}">
<multiselect:MultiSelectTreeView.Resources>
<Style x:Key="ExpandingImageStyle" TargetType="{x:Type Image}">
<Setter Property="Source" Value="{DynamicResource Icon_Closed}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=multiselect:MultiSelectTreeViewItem}, Path=IsExpanded}" Value="True">
<Setter Property="Source" Value="{DynamicResource Icon_Open}"/>
</DataTrigger>
</Style.Triggers>
</Style>
<Style x:Key="HighlightingTextStyle" TargetType="{x:Type Label}">
<Setter Property="FontWeight" Value="Regular"/>
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=multiselect:MultiSelectTreeViewItem}, Path=IsSelected}" Value="True">
<Setter Property="FontWeight" Value="Bold"/>
</DataTrigger>
</Style.Triggers>
</Style>
<ContextMenu x:Key="RootMenu">
<MenuItem Command="{Binding RefreshEvent}" Header="Refresh">
<MenuItem.Icon>
<Image Source="../Images/Icons/reboot.ico"/>
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
<ContextMenu x:Key="ChildMenu" >
<MenuItem Header="Get Configuration" Command="{Binding GetConfigurationEvent}">
<MenuItem.Icon>
<Image Source="../Images/Icons/download.ico"/>
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Put Configuration" Command="{Binding PutConfigurationEvent}">
<MenuItem.Icon>
<Image Source="../Images/Icons/upload.ico"/>
</MenuItem.Icon>
</MenuItem>
<Separator/>
<MenuItem Header="Put Configuration Binary (Hirschmann)" Command="{Binding PutConfigurationBinaryEvent}"/>
<MenuItem Header="Put Firmware" Command="{Binding PutFirmwareEvent}"/>
<Separator/>
<MenuItem Header="WPA2 Manual Update" Command="{Binding ManualUpdateConfigEvent}"/>
<MenuItem Header="WPA2 Periodic Update" Command="{Binding PeriodicUpdateConfigEvent}"/>
<Separator/>
<MenuItem Header="Secure Web Browser" Command="{Binding SecureWebBrowserEvent}"/>
<MenuItem Header="Connect SSH" Command="{Binding ConnectSSHEvent}"/>
<Separator/>
<MenuItem Header="Reboot Device" Command="{Binding RebootDevicesEvent}">
<MenuItem.Icon>
<Image Source="../Images/Icons/reboot.ico"/>
</MenuItem.Icon>
</MenuItem>
<Separator/>
<MenuItem Header="Put Https Certificate" Command="{Binding PutHttpsCertificateEvent}"/>
<MenuItem Header="Updating Firmware(Netbox LTE)" Command="{Binding UpdatingFirmwareNetboxEvent}"/>
<Separator/>
<MenuItem Header="Alstom Package's version" Command="{Binding AlstomPackageVersionEvent}"/>
</ContextMenu>
<converter:ContextMenuConverter x:Key="ContextMenuConverter"
RootMenu="{StaticResource RootMenu}"
ChildMenu="{StaticResource ChildMenu}"/>
</multiselect:MultiSelectTreeView.Resources>
<multiselect:MultiSelectTreeView.ItemContainerStyle>
<Style TargetType="{x:Type multiselect:MultiSelectTreeViewItem}">
<Setter Property="ContextMenu" Value="{Binding Converter={StaticResource ContextMenuConverter}}"/>
</Style>
</multiselect:MultiSelectTreeView.ItemContainerStyle>
<intractvty:Interaction.Behaviors>
<behaviours:BindableSelectedItemBehavior/>
</intractvty:Interaction.Behaviors>
<multiselect:MultiSelectTreeView.ItemTemplate>
<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}"/>
</StackPanel>
<HierarchicalDataTemplate.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Host}" DataType="{x:Type mod:HostGroup}">
<StackPanel Orientation="Horizontal">
<Image Style="{StaticResource ExpandingImageStyle}" Width="18" Height="18">
<Image.Resources>
<BitmapImage x:Key="Icon_Closed" UriSource="../Images/Icons/folder_closed.png"/>
<BitmapImage x:Key="Icon_Open" UriSource="../Images/Icons/folder_opened.png"/>
</Image.Resources>
</Image>
<Label Style="{StaticResource HighlightingTextStyle}" Content="{Binding GroupName}"/>
</StackPanel>
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate DataType="{x:Type mod:HostName}">
<StackPanel Orientation="Horizontal">
<Label Style="{StaticResource HighlightingTextStyle}" Content="{Binding Host}"/>
<Image Source="../Images/Icons/statusnone.ico"/>
</StackPanel>
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</multiselect:MultiSelectTreeView.ItemTemplate>
</multiselect:MultiSelectTreeView>
Continue reading...
System.Windows.Data Error: 40 : BindingExpression path error: 'RefreshEvent' property not found on 'object' ''RootNameList' (HashCode=49313939)'. BindingExpressionath=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 x:Name="Root" HorizontalAlignment="Stretch" Margin="0" BorderBrush="Gainsboro" Background="#FFF0EEEE" Width="250" VerticalAlignment="Stretch" ItemsSource="{Binding TreeViewDataCollection}">
<multiselect:MultiSelectTreeView.Resources>
<Style x:Key="ExpandingImageStyle" TargetType="{x:Type Image}">
<Setter Property="Source" Value="{DynamicResource Icon_Closed}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=multiselect:MultiSelectTreeViewItem}, Path=IsExpanded}" Value="True">
<Setter Property="Source" Value="{DynamicResource Icon_Open}"/>
</DataTrigger>
</Style.Triggers>
</Style>
<Style x:Key="HighlightingTextStyle" TargetType="{x:Type Label}">
<Setter Property="FontWeight" Value="Regular"/>
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=multiselect:MultiSelectTreeViewItem}, Path=IsSelected}" Value="True">
<Setter Property="FontWeight" Value="Bold"/>
</DataTrigger>
</Style.Triggers>
</Style>
<ContextMenu x:Key="RootMenu">
<MenuItem Command="{Binding RefreshEvent}" Header="Refresh">
<MenuItem.Icon>
<Image Source="../Images/Icons/reboot.ico"/>
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
<ContextMenu x:Key="ChildMenu" >
<MenuItem Header="Get Configuration" Command="{Binding GetConfigurationEvent}">
<MenuItem.Icon>
<Image Source="../Images/Icons/download.ico"/>
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Put Configuration" Command="{Binding PutConfigurationEvent}">
<MenuItem.Icon>
<Image Source="../Images/Icons/upload.ico"/>
</MenuItem.Icon>
</MenuItem>
<Separator/>
<MenuItem Header="Put Configuration Binary (Hirschmann)" Command="{Binding PutConfigurationBinaryEvent}"/>
<MenuItem Header="Put Firmware" Command="{Binding PutFirmwareEvent}"/>
<Separator/>
<MenuItem Header="WPA2 Manual Update" Command="{Binding ManualUpdateConfigEvent}"/>
<MenuItem Header="WPA2 Periodic Update" Command="{Binding PeriodicUpdateConfigEvent}"/>
<Separator/>
<MenuItem Header="Secure Web Browser" Command="{Binding SecureWebBrowserEvent}"/>
<MenuItem Header="Connect SSH" Command="{Binding ConnectSSHEvent}"/>
<Separator/>
<MenuItem Header="Reboot Device" Command="{Binding RebootDevicesEvent}">
<MenuItem.Icon>
<Image Source="../Images/Icons/reboot.ico"/>
</MenuItem.Icon>
</MenuItem>
<Separator/>
<MenuItem Header="Put Https Certificate" Command="{Binding PutHttpsCertificateEvent}"/>
<MenuItem Header="Updating Firmware(Netbox LTE)" Command="{Binding UpdatingFirmwareNetboxEvent}"/>
<Separator/>
<MenuItem Header="Alstom Package's version" Command="{Binding AlstomPackageVersionEvent}"/>
</ContextMenu>
<converter:ContextMenuConverter x:Key="ContextMenuConverter"
RootMenu="{StaticResource RootMenu}"
ChildMenu="{StaticResource ChildMenu}"/>
</multiselect:MultiSelectTreeView.Resources>
<multiselect:MultiSelectTreeView.ItemContainerStyle>
<Style TargetType="{x:Type multiselect:MultiSelectTreeViewItem}">
<Setter Property="ContextMenu" Value="{Binding Converter={StaticResource ContextMenuConverter}}"/>
</Style>
</multiselect:MultiSelectTreeView.ItemContainerStyle>
<intractvty:Interaction.Behaviors>
<behaviours:BindableSelectedItemBehavior/>
</intractvty:Interaction.Behaviors>
<multiselect:MultiSelectTreeView.ItemTemplate>
<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}"/>
</StackPanel>
<HierarchicalDataTemplate.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Host}" DataType="{x:Type mod:HostGroup}">
<StackPanel Orientation="Horizontal">
<Image Style="{StaticResource ExpandingImageStyle}" Width="18" Height="18">
<Image.Resources>
<BitmapImage x:Key="Icon_Closed" UriSource="../Images/Icons/folder_closed.png"/>
<BitmapImage x:Key="Icon_Open" UriSource="../Images/Icons/folder_opened.png"/>
</Image.Resources>
</Image>
<Label Style="{StaticResource HighlightingTextStyle}" Content="{Binding GroupName}"/>
</StackPanel>
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate DataType="{x:Type mod:HostName}">
<StackPanel Orientation="Horizontal">
<Label Style="{StaticResource HighlightingTextStyle}" Content="{Binding Host}"/>
<Image Source="../Images/Icons/statusnone.ico"/>
</StackPanel>
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</multiselect:MultiSelectTreeView.ItemTemplate>
</multiselect:MultiSelectTreeView>
Continue reading...