【发布时间】:2013-12-25 12:14:33
【问题描述】:
我正在 WPF 上编写一个简单的表单,它工作正常。但现在我应该将目标框架从 4 更改为 3.5。但是当我运行 3.5 版本时,它会因异常而失败。所以OnLoaded是这样的:
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
{
_notificator = new Notificator(Directory.GetCurrentDirectory());
_notificator.EventStarted += (o, ev) => Dispatcher.Invoke(new Action(() =>
{
new NotificationPage(ev).Show();
_collection.Remove(ev);
}));
_notificator.EventRemoved += (o, ev) => _collection.Remove(ev);
_notificator.EventAdded += (o, ev) => _collection.Insert(_notificator.Events.IndexOf(ev), ev);
_collection = new ObservableCollection<MyEvent>(_notificator.Events);
EventsGrid.DataContext = _collection;
_notificator.Start();
LostEventsGrid.DataContext = _notificator.LostEvents;
Hide();
}
我写了整个方法,但它只在使用Two-way binding requires Path or XPath 的隐藏方法上失败。堆栈跟踪:
в System.Windows.Data.BindingExpression.CreateBindingExpression(DependencyObject d, DependencyProperty dp, Binding binding, BindingExpressionBase parent) в System.Windows.Data.Binding.CreateBindingExpressionOverride(DependencyObject 目标,DependencyProperty dp,BindingExpressionBase 所有者) в System.Windows.Data.BindingOperations.SetBinding(DependencyObject 目标,DependencyProperty dp,BindingBase 绑定) в Microsoft.Windows.Controls.DataGridBoundColumn.ApplyBinding(DependencyObject 目标,DependencyProperty 属性) в Microsoft.Windows.Controls.DataGridTextColumn.GenerateElement(DataGridCell 单元格,对象数据项) в Microsoft.Windows.Controls.DataGridColumn.BuildVisualTree(Boolean isEditing, Object dataItem, DataGridCell cell) ? Microsoft.Windows.Controls.DataGridCell.BuildVisualTree() в Microsoft.Windows.Controls.DataGridCell.PrepareCell(对象项,DataGridRow ownerRow,Int32 索引) в Microsoft.Windows.Controls.DataGridCell.PrepareCell(对象项,ItemsControl cellsPresenter,DataGridRow ownerRow) в Microsoft.Windows.Controls.Primitives.DataGridCellsPresenter.PrepareContainerForItemOverride(DependencyObject 元素,对象项) • System.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.PrepareItemContainer(DependencyObject 容器,对象项) • System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.PrepareItemContainer(DependencyObject 容器) в Microsoft.Windows.Controls.DataGridCellsPanel.InsertContainer(Int32 childIndex, UIElement container, Boolean isRecycled) в Microsoft.Windows.Controls.DataGridCellsPanel.InsertNewContainer(Int32 childIndex, UIElement container) в Microsoft.Windows.Controls.DataGridCellsPanel.AddContainerFromGenerator(Int32 childIndex, UIElement child, Boolean newRealized) в Microsoft.Windows.Controls.DataGridCellsPanel.GenerateChild(IItemContainerGenerator 生成器,大小约束,DataGridColumn 列,Int32& childIndex,Size& childSize) в Microsoft.Windows.Controls.DataGridCellsPanel.GenerateChildren(IItemContainerGenerator 生成器,Int32 startIndex,Int32 endIndex,大小约束) в Microsoft.Windows.Controls.DataGridCellsPanel.GenerateAndMeasureChildrenForRealizedColumns(大小约束) в Microsoft.Windows.Controls.DataGridCellsPanel.MeasureOverride(大小约束) в System.Windows.FrameworkElement.MeasureCore(Size availableSize) в System.Windows.UIElement.Measure(Size availableSize) в MS.Internal.Helper.MeasureElementWithSingleChild(UIElement 元素,大小约束) в System.Windows.Controls.ItemsPresenter.MeasureOverride(大小约束) в System.Windows.FrameworkElement.MeasureCore(Size availableSize) в System.Windows.UIElement.Measure(Size availableSize) в System.Windows.Controls.Control.MeasureOverride(大小约束) в Microsoft.Windows.Controls.Primitives.DataGridCellsPresenter.MeasureOverride(Size availableSize) в System.Windows.FrameworkElement.MeasureCore(Size availableSize) в System.Windows.UIElement.Measure(Size availableSize) в System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV) в System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV) в System.Windows.Controls.Grid.MeasureOverride(大小约束) в System.Windows.FrameworkElement.MeasureCore(Size availableSize) в System.Windows.UIElement.Measure(Size availableSize) в System.Windows.Controls.Border.MeasureOverride(大小约束) в System.Windows.FrameworkElement.MeasureCore(Size availableSize) в System.Windows.UIElement.Measure(Size availableSize) в System.Windows.Controls.Control.MeasureOverride(大小约束) в System.Windows.FrameworkElement.MeasureCore(Size availableSize) в System.Windows.UIElement.Measure(Size availableSize) в System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(大小约束) в Microsoft.Windows.Controls.Primitives.DataGridRowsPresenter.MeasureOverride(大小约束) в System.Windows.FrameworkElement.MeasureCore(Size availableSize) в System.Windows.UIElement.Measure(Size availableSize) ? System.Windows.ContextLayoutManager.UpdateLayout() в System.Windows.Interop.HwndSource.Process_WM_SIZE(UIElement rootUIElement, IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) в System.Windows.Interop.HwndSource.LayoutFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& 处理) в MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& 处理) в MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) в System.Windows.Threading.ExceptionWrapper.InternalRealCall(委托回调,对象参数,布尔isSingleParameter) в System.Windows.Threading.ExceptionWrapper.TryCatchWhen(对象源,委托回调,对象参数,布尔isSingleParameter,委托catchHandler) в System.Windows.Threading.Dispatcher.WrappedInvoke(委托回调,对象参数,布尔isSingleParameter,委托catchHandler) в System.Windows.Threading.Dispatcher.WrappedInvoke(委托回调,对象参数,布尔isSingleParameter) в System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority 优先级,TimeSpan 超时,委托方法,对象参数,布尔 isSingleParameter) в System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority 优先级,委托方法,对象 arg) в MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) в MS.Win32.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam) в MS.Win32.HwndSubclass.DefWndProcWrapper(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) в MS.Win32.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam) в MS.Win32.HwndSubclass.CallOldWindowProc(IntPtr oldWndProc, IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) в MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
在 .net 4+ 中运行良好
【问题讨论】:
标签: c# .net wpf windows .net-3.5