Unplanned
Last Updated: 12 Nov 2025 07:48 by Stenly
Stenly
Created on: 12 Nov 2025 07:48
Category: RichTextBox
Type: Bug Report
0
RichTextBox: A NullReferenceException is raised when having analytics and working with the RadContextMenu

Working with the RadContextMenu that comes from the RadRichTextBoxUI, when having analytics enabled, produces a NullReferenceException.

Manually set the Menu property on the PreviewMouseLeftButtonUp event of the RadMenuItem:

static MainWindow()
{
    EventManager.RegisterClassHandler(typeof(RadMenuItem), PreviewMouseLeftButtonUpEvent, new MouseButtonEventHandler(OnRadMenuItemPreviewMouseLeftButtonUp), true);
}

private static void OnRadMenuItemPreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
    RadMenuItem radMenuItem = (RadMenuItem)sender;

    RadContextMenu radContextMenu = radMenuItem.ParentOfType<RadContextMenu>();

    if (radContextMenu != null)
    {
        PropertyInfo menuPropertyInfo = radMenuItem.GetType().GetProperty("Menu", BindingFlags.Public | BindingFlags.Instance);
        if (menuPropertyInfo != null)
        {
            MethodInfo setMethod = menuPropertyInfo.GetSetMethod(true);
            if (setMethod != null)
            {
                Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                {
                    setMethod.Invoke(radMenuItem, new object[] { radContextMenu });
                }), System.Windows.Threading.DispatcherPriority.Background);
            }
        }
    }
}

0 comments