Question

I'm writing a simple form on WPF, and it works fine. But now I should change target framework from 4 to 3.5. But when i'm running 3.5 version, it fails with excepton. So OnLoaded is like this:

    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();
    }

I wrote entire method, but it fails only on Hide method with Two-way binding requires Path or XPath. Stacktrace:

в System.Windows.Data.BindingExpression.CreateBindingExpression(DependencyObject d, DependencyProperty dp, Binding binding, BindingExpressionBase parent) в System.Windows.Data.Binding.CreateBindingExpressionOverride(DependencyObject target, DependencyProperty dp, BindingExpressionBase owner) в System.Windows.Data.BindingOperations.SetBinding(DependencyObject target, DependencyProperty dp, BindingBase binding) в Microsoft.Windows.Controls.DataGridBoundColumn.ApplyBinding(DependencyObject target, DependencyProperty property) в Microsoft.Windows.Controls.DataGridTextColumn.GenerateElement(DataGridCell cell, Object dataItem) в Microsoft.Windows.Controls.DataGridColumn.BuildVisualTree(Boolean isEditing, Object dataItem, DataGridCell cell) в Microsoft.Windows.Controls.DataGridCell.BuildVisualTree() в Microsoft.Windows.Controls.DataGridCell.PrepareCell(Object item, DataGridRow ownerRow, Int32 index) в Microsoft.Windows.Controls.DataGridCell.PrepareCell(Object item, ItemsControl cellsPresenter, DataGridRow ownerRow) в Microsoft.Windows.Controls.Primitives.DataGridCellsPresenter.PrepareContainerForItemOverride(DependencyObject element, Object item) в System.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.PrepareItemContainer(DependencyObject container, Object item) в System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.PrepareItemContainer(DependencyObject container) в 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 newlyRealized) в Microsoft.Windows.Controls.DataGridCellsPanel.GenerateChild(IItemContainerGenerator generator, Size constraint, DataGridColumn column, Int32& childIndex, Size& childSize) в Microsoft.Windows.Controls.DataGridCellsPanel.GenerateChildren(IItemContainerGenerator generator, Int32 startIndex, Int32 endIndex, Size constraint) в Microsoft.Windows.Controls.DataGridCellsPanel.GenerateAndMeasureChildrenForRealizedColumns(Size constraint) в Microsoft.Windows.Controls.DataGridCellsPanel.MeasureOverride(Size constraint) в System.Windows.FrameworkElement.MeasureCore(Size availableSize) в System.Windows.UIElement.Measure(Size availableSize) в MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) в System.Windows.Controls.ItemsPresenter.MeasureOverride(Size constraint) в System.Windows.FrameworkElement.MeasureCore(Size availableSize) в System.Windows.UIElement.Measure(Size availableSize) в System.Windows.Controls.Control.MeasureOverride(Size constraint) в 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(Size constraint) в System.Windows.FrameworkElement.MeasureCore(Size availableSize) в System.Windows.UIElement.Measure(Size availableSize) в System.Windows.Controls.Border.MeasureOverride(Size constraint) в System.Windows.FrameworkElement.MeasureCore(Size availableSize) в System.Windows.UIElement.Measure(Size availableSize) в System.Windows.Controls.Control.MeasureOverride(Size constraint) в System.Windows.FrameworkElement.MeasureCore(Size availableSize) в System.Windows.UIElement.Measure(Size availableSize) в System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(Size constraint) в Microsoft.Windows.Controls.Primitives.DataGridRowsPresenter.MeasureOverride(Size constraint) в 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& handled) в MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) в MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) в System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter) в System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler) в System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler) в System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter) в System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter) в System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object 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)

in .net 4+ it works fine

Était-ce utile?

La solution 2

Solved : problem was in WPFToolkit, because of using DataGrid, that doesn't exists in WPF3.5. So i've referenced it, and i still get errors on .Net 4+ too, when using controls from WPFToolkit instead of inner frameworks.

Autres conseils

For others that may have this issue. My issue was I was how I setup my binding path. I was chaining my path and whenever any reference up the chain changes, the control losses its ability to bind and throws the Two-way binding requires Path or XPath exception.

Consider the example:

<Binding Path="EntityProperty.Name" Mode="TwoWay">

Whenever the EntityProperty reference changes then the control will loose it's binding path and throw the exception.

See the following post for a few workarounds: https://stackoverflow.com/a/6250988/176728

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top