2014-01-13 37 views
2

我在设计器中出现这个奇怪的错误。
Visual Studio 2013 WPF - 其他视图/窗口工作正常。 这是发生在我有设计时间数据(如果我删除设计时间数据,它工作正常)。WPF Visual Studio Designer中的错误

System.NullReferenceException对象引用未设置为对象的实例 。
在 System.Windows.Controls.GridViewHeaderRowPresenter.OnLayoutUpdated(对象 发件人,EventArgs的)
在 System.Windows.ContextLayoutManager.fireLayoutUpdateEvent()
在 System.Windows.ContextLayoutManager.UpdateLayout()
在 System.Windows .UIElement.UpdateLayout()
在 System.Windows.Interop.HwndSource.SetLayoutSize()
在 System.Windows.Interop.HwndSource.set_RootVisualInternal(视觉值)
在System.Windows.Interop.HwndSource.set_RootVisual(视觉值)
at Microsoft.Expression.DesignHost.Isolation.Remoting.RemoteUIElement。 <> c__DisplayClass10.b__f()
at Microsoft.Expression.DesignHost.Isolation.Remoting.ThreadMarshaler。 <> c__DisplayClass2a`1.b__29()
在 Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.Call.InvokeWorker()
在 Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.Call.Invoke(布尔 waitingInExternalCall)
在< Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.InvokeCall(呼叫 调用)
在 Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.ProcessQueue(CallQueue 队列)
在 Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.P rocessInboundAsyncQueue(的Int32 同一性)
在 Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.ProcessMessage(的Int32 味精,IntPtr的wParam中,IntPtr的lParam的,布尔elevatedQuery,布尔& 处理)
在 Microsoft.Expression.DesignHost。 Isolation.Remoting.STAMarshaler.OnWindowMessage(IntPtr的 HWND,MSG的Int32,IntPtr的wParam中,IntPtr的lParam的,布尔&处理)
在 Microsoft.Expression.DesignHost.Isolation.Remoting.MessageOnlyHwndWrapper.WndProc(IntPtr的 HWND,MSG的Int32,IntPtr的wParam,IntPtr lParam)
at MS.Win32.UnsafeNativeMethod s.DispatchMessage在 System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame 帧)
在 System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame帧)
在System.Windows.Threading程序(MSG & MSG)
。 Dispatcher.Run()
在 System.Windows.Application.RunDispatcher(对象忽略)
在 System.Windows.Application.RunInternal(窗口窗口)
在 System.Windows.Application.Run(窗口窗口)
在 Microsoft.Expression.DesignHost.Isolation.DesignerProcess。RunApplication()
at Microsoft.Expression.DesignHost.Isolation.DesignerProcess。 <> c__DisplayClass2.b__0()
在System.Threading.ThreadHelper.ThreadStart_Context(对象状态)
在System.Threading.ExecutionContext.RunInternal(的ExecutionContext 的ExecutionContext,ContextCallback回调,对象的状态,布尔 preserveSyncCtx)
在 系统.Threading.ExecutionContext.Run(的ExecutionContext 的ExecutionContext,ContextCallback回调,对象的状态,布尔 preserveSyncCtx)
在 System.Threading.ExecutionContext.Run(的ExecutionContext 的ExecutionContext,ContextCallback回调,对象状态)
在 SYSTE m.Threading.ThreadHelper.ThreadStart()

错误 Error

+0

视图的代码隐藏功能在设计时无法使用。也许类字段不是通过“默认构造函数”代码路径初始化的。使用设计时检查描述在http://stackoverflow.com/questions/3978264/how-to-check-if-im-in-run-time-or-design-time –

+0

分享你的xaml,看起来像你的罪魁祸首在于它。 –

+0

@ChrisW不是xaml实际上是一个转换器,没有检查为空,是我加了一个空检查它工作正常 - – DermFrench

回答

3

这是造成不检查空一些转换器的图片: 我在支票增值== null,并且所有的罚款再次。

public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 

    { 
     if (value == null) { return "White"; } 
     var valueAsString = (string)value; 

     if (String.IsNullOrWhiteSpace(valueAsString)) 
     { 
      return "White"; 
     } 

     if (valueAsString.ToLower().Contains("Late".ToLower())) 
     { 
      return "Yellow"; 
     } 
     return "White";   
    } 

MSDN也有设计时的错误这里一些提示: http://msdn.microsoft.com/query/dev12.query?appId=Dev12IDEF1&l=EN-US&k=k(VS.XamlDesigner.ExceptionUI);k(TargetFrameworkMoniker-.NETFramework,Version%3Dv4.0)&rd=true

值转换 您的自定义的IValueConverter实现应当检查空,在转换方法的第一个参数预期的类型。如果值转换器没有正确实现,以下XAML将显示绑定到Application.Current的设计时失败。

+0

将修复应用程序,也将解决这一个? – RoCk