NotImplementedException System.Windows.Clipboard.GetDataObjectInternal()

时间:2016-12-14 12:12:50

标签: c# .net wpf

我从未见过这个错误,它是由.net代码本身抛出的:

System.NotImplementedException: O método ou a operação não está implementada.
   em System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   em System.Windows.Clipboard.GetDataObjectInternal()
   em System.Windows.Documents.TextEditorCopyPaste.OnQueryStatusPaste(Object target, CanExecuteRoutedEventArgs args)
   em System.Windows.Input.CommandBinding.OnCanExecute(Object sender, CanExecuteRoutedEventArgs e)
   em System.Windows.Input.CommandManager.FindCommandBinding(Object sender, RoutedEventArgs e, ICommand command, Boolean execute)
   em System.Windows.Input.CommandManager.OnCanExecute(Object sender, CanExecuteRoutedEventArgs e)
   em System.Windows.UIElement.OnCanExecuteThunk(Object sender, CanExecuteRoutedEventArgs e)
   em System.Windows.Input.CanExecuteRoutedEventArgs.InvokeEventHandler(Delegate genericHandler, Object target)
   em System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   em System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   em System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   em System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   em System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
   em System.Windows.Input.RoutedCommand.CriticalCanExecuteWrapper(Object parameter, IInputElement target, Boolean trusted, CanExecuteRoutedEventArgs args)
   em System.Windows.Input.RoutedCommand.CanExecuteImpl(Object parameter, IInputElement target, Boolean trusted, Boolean& continueRouting)
   em System.Windows.Input.RoutedCommand.CriticalCanExecute(Object parameter, IInputElement target, Boolean trusted, Boolean& continueRouting)
   em System.Windows.Input.CommandManager.TransferEvent(IInputElement newSource, CanExecuteRoutedEventArgs e)
   em System.Windows.Input.CommandManager.OnCanExecute(Object sender, CanExecuteRoutedEventArgs e)
   em System.Windows.UIElement.OnCanExecuteThunk(Object sender, CanExecuteRoutedEventArgs e)
   em System.Windows.Input.CanExecuteRoutedEventArgs.InvokeEventHandler(Delegate genericHandler, Object target)
   em System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   em System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   em System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   em System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   em System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
   em System.Windows.Input.RoutedCommand.CriticalCanExecuteWrapper(Object parameter, IInputElement target, Boolean trusted, CanExecuteRoutedEventArgs args)
   em System.Windows.Input.RoutedCommand.CanExecuteImpl(Object parameter, IInputElement target, Boolean trusted, Boolean& continueRouting)
   em System.Windows.Input.RoutedCommand.CriticalCanExecute(Object parameter, IInputElement target, Boolean trusted, Boolean& continueRouting)
   em MS.Internal.Commands.CommandHelpers.CanExecuteCommandSource(ICommandSource commandSource)
   em System.Windows.Controls.MenuItem.UpdateCanExecute()
   em System.Windows.Controls.MenuItem.OnCanExecuteChanged(Object sender, EventArgs e)
   em System.Windows.Input.CanExecuteChangedEventManager.HandlerSink.OnCanExecuteChanged(Object sender, EventArgs e)
   em System.Windows.WeakEventManager.ListenerList.DeliverEvent(Listener& listener, Object sender, EventArgs args, Type managerType)
   em System.Windows.WeakEventManager.ListenerList.DeliverEvent(Object sender, EventArgs args, Type managerType)
   em System.Windows.WeakEventManager.DeliverEvent(Object sender, EventArgs args)
   em System.Windows.Input.CommandManager.RequerySuggestedEventManager.OnRequerySuggested(Object sender, EventArgs args)
   em System.Windows.Input.CommandManager.RaiseRequerySuggested(Object obj)
   em System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   em System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

当我右键单击TextBox时,它发生在我的WPF应用程序中。右键单击TextBox时,它通常显示CTRL + C CTRL + V命令。

修改

没有 处理程序用于复制,粘贴,剪切,但是我创建了自己的上下文菜单,因为我添加了另一个菜单项。我用Behavior

做了
internal class VariableSelectorBehavior : Behavior<TextBox>
    {

        protected override void OnAttached()
        {
            base.OnAttached();

                AssociatedObject.ContextMenu = CreateContextMenu();
        }

        private ContextMenu CreateContextMenu()
        {
            var viewModel = new VariableSelectorViewModel(IoC.Get<IVariableList>(), IsRequired, DataType);
            viewModel.VariableSelected += VariableSelected;

            var variableMenu = new MenuItem { Header = "Variables" };
            variableMenu.DataContext = viewModel;
            variableMenu.AddHandler(MenuItem.ClickEvent, new RoutedEventHandler(VariableMenuItemClick));
            variableMenu.SetBinding(MenuItem.ItemsSourceProperty, new Binding("Items"));
            variableMenu.SetBinding(MenuItem.VisibilityProperty, new Binding("HasItems")
            {
                Source = variableMenu,
                Converter = new BooleanToVisibilityConverter()
            });

            var separator = new Separator();
            separator.SetBinding(MenuItem.VisibilityProperty, new Binding("HasItems")
            {
                Source = variableMenu,
                Converter = new BooleanToVisibilityConverter()
            });

            var menu = new ContextMenu();
            menu.Items.Add(variableMenu);
            menu.Items.Add(separator);
            menu.Items.Add(new MenuItem { Command = ApplicationCommands.Cut });
            menu.Items.Add(new MenuItem { Command = ApplicationCommands.Copy });
            menu.Items.Add(new MenuItem { Command = ApplicationCommands.Paste });

            return menu;
        }
}

不幸的是,我无法重现这一点,有几次我试过了。有没有人知道这里发生了什么?

0 个答案:

没有答案