1

Resolved

Designer Error in VS 2010

description

Upgraded Example to VS2010 and rebuilt all. VS 2010 designer errors out.
 
System.NullReferenceException
Object reference not set to an instance of an object.
at WPF.MDI.MdiContainer.MdiContainer_Loaded(Object sender, RoutedEventArgs e)
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.UIElement.RaiseEvent(RoutedEventArgs e)
at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root)
at MS.Internal.LoadedOrUnloadedOperation.DoWork()
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 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

comments

metator wrote Jun 16, 2010 at 1:24 PM

I don't know if this is the right solution but i've managed to solve this error by changing the code in MdiContainer.MdiContainer_Loaded method:

private void MdiContainer_Loaded(object sender, RoutedEventArgs e) {
        Window win = Window.GetWindow(this);
        if (win != null) {
            win.Activated += new EventHandler(MdiContainer_Activated);
            win.Deactivated += new EventHandler(MdiContainer_Deactivated);
        }

        windowCanvas.Width = windowCanvas.ActualWidth;
        windowCanvas.Height = windowCanvas.ActualHeight;

        windowCanvas.VerticalAlignment = VerticalAlignment.Top;
        windowCanvas.HorizontalAlignment = HorizontalAlignment.Left;

        InvalidateSize();
    }
HTH. Regards,

Mach

d4anmol wrote Nov 12, 2010 at 11:53 AM

Good Work Mach.
The code is very much right.

private void MdiContainer_Loaded(object sender, RoutedEventArgs e) {
Window win = Window.GetWindow(this);
if (win != null) {
win.Activated += new EventHandler(MdiContainer_Activated);
win.Deactivated += new EventHandler(MdiContainer_Deactivated);
}

windowCanvas.Width = windowCanvas.ActualWidth;
windowCanvas.Height = windowCanvas.ActualHeight;

windowCanvas.VerticalAlignment = VerticalAlignment.Top;
windowCanvas.HorizontalAlignment = HorizontalAlignment.Left;

InvalidateSize();

}

Error is occur only because window object is null & we can't assign event handler to a null object.


Regards,

Deepak Anmol
(MCTS)

wrote Dec 11, 2010 at 4:12 PM

wrote Dec 11, 2010 at 4:13 PM

wrote Dec 11, 2010 at 7:20 PM

wrote Feb 25, 2011 at 12:17 PM

wrote Feb 21, 2013 at 11:13 PM

wrote May 16, 2013 at 10:45 AM

wrote May 16, 2013 at 10:45 AM

wrote Jun 14, 2013 at 7:25 AM