MahApps / MahApps.Metro

A framework that allows developers to cobble together a better UI for their own WPF applications with minimal effort.
https://mahapps.com
MIT License
9.21k stars 2.45k forks source link

designer issue #4490

Open TheCamel opened 1 month ago

TheCamel commented 1 month ago

Describe the bug

I have a hamburgerMeun in a user control...designer display well

but this user control is included into a MetroWindow and and it crash the designer like below

even if i remove the handler :-(

<mah:HamburgerMenu x:Name="HamburgerMenuControl"
                   DisplayMode="CompactOverlay"
                   HamburgerWidth="48"
                   CanResizeOpenPane="False"
                   ItemTemplate="{StaticResource HamburgerMenuItem}"
                   OptionsItemTemplate="{StaticResource HamburgerOptionsMenuItem}"
                   **ItemInvoked="HamburgerMenuControl_ItemInvoked"**
                   SelectedIndex="0"
                   IsPaneOpen="False"
                   OptionsItemClick="HamburgerMenuControl_OptionsItemClick">

Environment

MahApps.Metro version: alpha 0492 Target Framework: .Net Core 8

   at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
   at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Delegate.DynamicInvokeImpl(Object[] args)
   at System.Windows.RoutedEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at MahApps.Metro.Controls.HamburgerMenu.RaiseItemEvents(Object selectedItem) in C:\projects\mahapps-metro\src\MahApps.Metro\Controls\HamburgerMenu\HamburgerMenu.Events.cs:line 139
   at MahApps.Metro.Controls.HamburgerMenu.HamburgerMenu_Loaded(Object sender, RoutedEventArgs e) in C:\projects\mahapps-metro\src\MahApps.Metro\Controls\HamburgerMenu\HamburgerMenu.cs:line 91
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
   at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root)
   at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks()
   at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
   at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
   at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
timunie commented 1 month ago

please attach a minimal sample. Also the StackTrace seems to be incomplete, please post the entire error message printed.

TheCamel commented 1 month ago

I can't it's prod application too complex...and the trace is from the designer windows of visual... I will investiguate to see if i can find out more

punker76 commented 1 month ago

@TheCamel Which version of VS do you use?

TheCamel commented 1 month ago

@punker76 Microsoft Visual Studio Professional 2022 (64 bits) - Current Version 17.9.6

TheCamel commented 1 month ago

I tried to debug visual with another visual, but can't get any "catch". May be I have to include the mahapps project in my solution. I used the trick from here https://docs.devexpress.com/GeneralInformation/403685/support-services/obtain-exception-call-stack#get-exception-call-stack-of-design-time-errors-in-visual-studio

TheCamel commented 16 hours ago

@punker76

I avoid the crash by testing the design property

private void HamburgerMenuControl_ItemInvoked(object sender, HamburgerMenuItemInvokedEventArgs args) { if (args.IsItemOptions || System.ComponentModel.DesignerProperties.GetIsInDesignMode(this) ) { return; }

TheCamel commented 13 hours ago

In fact in handler i have the commented line below at the end that cause the exception in the main window, but not in the user control itself. I will try to write it more secure=> nothing change, same crash Danke. btw i would prefer an update on the other HamburgerMenu issue....tchu$$

private void HamburgerMenuControl_ItemInvoked(object sender, HamburgerMenuItemInvokedEventArgs args)
{
    if (args.IsItemOptions)
    {
        return;
    }

    HamburgerMenuControl.Content = args.InvokedItem;

    // close the menu if a item was selected
    if (HamburgerMenuControl.IsPaneOpen)
    {
        HamburgerMenuControl.IsPaneOpen = false;
    }

    **//((HomeViewModel)DataContext).CurrentView = (ObservableRecipient)((UserControl)((HamburgerMenuIconItem)args.InvokedItem).Tag).DataContext;**
}