Hi,
we have NetAdvantage for WPF (v2011.2). I can't use the xamContext menu because a null reference exception is thrown if the menuItem is clicked.
I tried Service Release 2, and hoped that this bug has been fixed "Element hosted menu throwing NullReferenceException during GetClickedElements method." But it didn't help. Same behavior as before.
Here is the stacktrace:
System.NullReferenceException: Object reference not set to an instance of an object. at Infragistics.Controls.Menus.XamMenuItem.RaiseClickEvent() at Infragistics.Controls.Menus.XamMenuItem.HandleItemSelection() at Infragistics.Controls.Menus.XamMenuItem.OnMouseLeftButtonUp(MouseButtonEventArgs e) at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e) at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent) at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e) at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) at System.Windows.ContentElement.RaiseTrustedEvent(RoutedEventArgs args) at System.Windows.Input.InputManager.ProcessStagingArea() at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input) at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport) at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel) at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
Our xaml is:
<DataTemplate x:Key="TreeItemTemplate"> <StackPanel Orientation="Horizontal" Margin="-3"> <!--StackPanel.ContextMenu> <ContextMenu Visibility="{Binding Path=Data.ContextMenu.Visibility}" ItemsSource="{Binding Path=Data.ContextMenu.MenuItems}"/> </StackPanel.ContextMenu--> <!-- xamContextMenu bug? null reference exception on Click event! --> <ig:ContextMenuService.Manager> <ig:ContextMenuManager> <ig:ContextMenuManager.ContextMenu> <ig:XamContextMenu Visibility="{Binding Path=Data.ContextMenu.Visibility}" ItemsSource="{Binding Path=Data.ContextMenu.MenuItems}" HierarchicalItemTemplate="{StaticResource MenuItemTemplate}" ItemContainerStyleSelector="{StaticResource menuSeparatorStyleSelector}" /> </ig:ContextMenuManager.ContextMenu> </ig:ContextMenuManager> </ig:ContextMenuService.Manager> <Image Name="groupImg" Width="16" Height="14" Source="{Binding Data.GroupIcon}" VerticalAlignment="Center" /> <Image Width="16" Height="14" Margin="3" Source="{Binding Data.Icon}" VerticalAlignment="Center" /> <TextBlock Name="nodeTxt" Text="{Binding Data.Text}" Foreground="{Binding Data.TextColor}" FontWeight="{Binding Data.FontWeight}" VerticalAlignment="Center"/> </StackPanel> <DataTemplate.Triggers> <!-- Only show group icon if not null --> <DataTrigger Binding="{Binding Data.GroupIcon}" Value="{x:Null}"> <Setter TargetName="groupImg" Property="Visibility" Value="Collapsed" /> </DataTrigger> </DataTemplate.Triggers> </DataTemplate>
Please let me know if you need more input. Thanks in advance.
Hello,
The development issue with ID of 108776 has been fixed and it is available in the latest Service Release. You can download the Service Release by logging in our web site and then going to Account\My Keys and Downloads page.
Thank you for using Infragistics Components.
Sincerely,
Krasimir
Developer Support Engineer
Infragistics
www.infragistics.com/support
Hello Ron,
I have created a support ticket on your behalf with number CAS-91952-LWQMD2 in order to link the development issue 108776 to it so that you are automatically updated when a Service Release containing your fix is available for download. Also the issue is already fixed in our latest internal builds and the fix should be available for you to download with the next service release: http://es.infragistics.com/support/service-releases.aspx#ServiceReleases
Infragistics, Inc.
I am also having a problem with this null exception.
In my case, I have a ListBox, with a Grid for each item, on TextBlock in the grid, I want to right click and select an item, but the list of items to select from depends on the row in the ListBox selected. So I can't set the ItemsSource in code as per your example.
Is it possible to do what I have outlined?
Attached is a simplified example of what I am trying to do.
Thanks for your help.
Ron.
I am very glad that you have managed to solve the issue that you are having. Please let me know if you need any further assistance on the matter.
Finally I got it working. The key was to apply the DefaultItemsContainer also for the XamContextMenu itself.
<!-- Menu / Context Menu --> <Image x:Key="MenuImg" Height="16" Width="16" VerticalAlignment="Center" Source="{Binding Icon}" x:Shared="false"/> <DataTemplate x:Key="XamMenuItemTemplate"> <ig:XamMenuItem Visibility="{Binding Visibility}" IsCheckable="{Binding IsCheckable}" IsChecked="{Binding IsChecked, Mode=TwoWay}" IsEnabled="{Binding IsEnabled}" ToolTip="{Binding ToolTip}" Icon="{StaticResource MenuImg}"> <i:Interaction.Triggers> <i:EventTrigger EventName="Click"> <i:InvokeCommandAction Command="{Binding Command}" /> </i:EventTrigger> </i:Interaction.Triggers> </ig:XamMenuItem> </DataTemplate > <Style TargetType="{x:Type ig:XamMenuItem}" x:Key="menuSeparatorStyle"> <Setter Property="Template" > <Setter.Value> <ControlTemplate> <ig:XamMenuSeparator/> </ControlTemplate> </Setter.Value> </Setter> </Style> <ig:HierarchicalDataTemplate x:Key="MenuItemTemplate" ItemsSource="{Binding MenuItems}" DefaultItemsContainer="{StaticResource XamMenuItemTemplate}"> <DataTemplate> <AccessText Text="{Binding Text}"/> </DataTemplate> </ig:HierarchicalDataTemplate> <DataTemplate x:Key="TreeItemTemplate"> <StackPanel Orientation="Horizontal" Margin="-3"> <ig:ContextMenuService.Manager> <ig:ContextMenuManager> <ig:ContextMenuManager.ContextMenu> <ig:XamContextMenu Visibility="{Binding Path=Data.ContextMenu.Visibility}" ItemsSource="{Binding Path=Data.ContextMenu.MenuItems}" HierarchicalItemTemplate="{StaticResource MenuItemTemplate}" ItemContainerStyleSelector="{StaticResource menuSeparatorStyleSelector}" DefaultItemsContainer="{StaticResource XamMenuItemTemplate}" Loaded="XamContextMenu_Loaded"> <i:Interaction.Triggers> <i:EventTrigger EventName="Opened"> <i:InvokeCommandAction Command="{Binding Data.ContextMenuOpenedCommand}" /> </i:EventTrigger> </i:Interaction.Triggers> </ig:XamContextMenu> </ig:ContextMenuManager.ContextMenu> </ig:ContextMenuManager> </ig:ContextMenuService.Manager> <Image Name="groupImg" Width="16" Height="14" Source="{Binding Data.GroupIcon}" VerticalAlignment="Center" /> <Image Width="16" Height="14" Margin="3" Source="{Binding Data.Icon}" VerticalAlignment="Center" /> <TextBlock Name="nodeTxt" Text="{Binding Data.Text}" Foreground="{Binding Data.TextColor}" FontWeight="{Binding Data.FontWeight}" VerticalAlignment="Center"/> </StackPanel> <DataTemplate.Triggers> <!-- Only show group icon if not null --> <DataTrigger Binding="{Binding Data.GroupIcon}" Value="{x:Null}"> <Setter TargetName="groupImg" Property="Visibility" Value="Collapsed" /> </DataTrigger> </DataTemplate.Triggers> </DataTemplate>