在DocumentViewer中右键单击TextBox时发生异常 [英] Exception while Right-Click on TextBox within DocumentViewer

查看:46
本文介绍了在DocumentViewer中右键单击TextBox时发生异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我正在创建简单的DocumentViewer,然后将Xps文档加载到其中,然后在文档的第一页上创建TextBox控件.右键单击TextBox会导致从 PresentationCore 引发的不清楚的异常,我无法调试也不能低估该异常.任何帮助表示赞赏.详细信息在下面.

我有以下 XAML :

Hello,

I'm creating simple DocumentViewer, then load Xps document into it, then create the TextBox control on the first page of the document. Right-click on the TextBox leads to unclear exception thrown from PresentationCore , which I cannot debug nor understant. Any help is appreciated. Details go below.

I have  the following XAML :

<Window x:Class="Test.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Grid>
        <DocumentViewer Name="documentViewer">
            
        </DocumentViewer>
    </Grid>
</Window>

以及以下代码:

And the following code :

	public partial class Window1 : Window
	{
		public Window1()
		{
			InitializeComponent();
			XpsDocument xpsDocument = new XpsDocument("C:/Temp/test.xps", FileAccess.Read);
			FixedDocumentSequence docSequence = xpsDocument.GetFixedDocumentSequence();
			FixedDocument doc = docSequence.References[0].GetDocument(false);
			documentViewer.Document = doc;
			PageContent pageContent = doc.Pages[0];
			FixedPage fixedPage = pageContent.GetPageRoot(false);

			TextBox tb = new TextBox();
			tb.Width = 100;
			tb.Height = 100;

			fixedPage.Children.Add(tb);			
		}
	}

基本上我是怎么做的:

Basically what I do:

  1. 我加载Xps文档并在DocumentViewer中显示
  2. 创建TextBox控件并将其添加到FixedDocument第一页的Children集合中

一切正常,但是如果我在运行时右键单击TextBox,我会立即从 PresentationFramework 收到以下异常:

消息: 不能将"System.Windows.Data.MultiBindingExpression"值分配给对象"System.Windows.Controls.Primitives.RepeatButton"的属性"Visibility".找不到与"und"相关的非中性文化.对象'System.Windows.Data.MultiBinding'出错."

堆栈:
在System.Windows.Markup.XamlParseException.ThrowException(字符串消息,异常innerException,Int32 lineNumber,Int32 linePosition,Uri baseUri,XamlObjectIds currentXamlObjectIds,XamlObjectIds contextXamlObjectIds,Type objectType)
在System.Windows.Markup.XamlParseException.ThrowException(ParserContext parserContext,Int32 lineString ,在System.Windows.Markup.BamlRecordReader.SetDependencyComplexProperty(Object currentTarget,BamlAttributeInfoRecord attribInfo,Object o)处异常

在System.Windows.Markup.BamlRecordReader.SetPropertyValueToParent(Boolean fromStartTag,Boolean& isMarkupExtension)
在System.Windows.Markup.BamlRecordReader.ReadElementEndRecord(NestedBamlRecordReader中的布尔值)
在System.Windows.Markup.BamlRecordReader.ReadRecord(BamlRecord bamlRecord)
System.Windows.StyleHelper.LoadOptimizedTemplateContent(DependencyObject容器,ParserContext parserContext,OptimizedTemplateContent优化的模板内容,FrameworkTemplate框架模板,IComponentConnector componentConnector,IStyleConnector styleConnector,列出1受影响的孩子,Uncommonmon`1 templatedNonFeChildrenField)在System.Windows.FrameworkObject.LoadContent(Dependency)容器,在System.Windows.StyleHelper.ApplyTemplateContent(UncommonField`1 dataField,DependencyObject container,FrameworkElementFactory templateRoot,Int32 lastChildIndex,HybridDictionary childIndexFromChildID,FrameworkTemplate frameworkTemplate)处位于List.1受影响的孩子,UncommonField`1 templatedNonFeChildrenField)
System.Windows.FrameworkElement.ApplyTemplateContent(UncommonField`1 templateDataField,FrameworkElement容器)
lableSize)
在System.Windows.UIElement.Measure(大小availableSize)
在System.Windows.Controls.Grid.MeasureOverride(大小约束)
在System.Windows.FrameworkElement.MeasureCore(Size在System.Windows.UIElement.Measure(可用大小)
在System.Windows.Controls.Border.MeasureOverride(大小约束)在System.Windows.FrameworkElement.MeasureCore(大小)在System.Windows.UIElement.Measure(可用大小)
上System.Windows.Controls.Decorator.MeasureOverride(尺寸约束)在System.Windows.FrameworkElement.MeasureCore(大小上可用)在System.Windows.UIElement.Measure(可用大小)
在System.Windows.Controls.Control.MeasureOverride(大小约束)在System.Windows.FrameworkElement.MeasureCore(大小可用)
在System.Windows.UIElement.Measure处的availableSize)
(大小availableSize)在System.Windows.Controls.Decorator.MeasureOverride(处c的大小处可用) onstraint)
在System.Windows.Documents.AdornerDecorator.MeasureOverride(大小约束)
在System.Windows.FrameworkElement.MeasureCore(Size availableSize)
在System.Windows.UIElement.Measure(Size在System.Windows.Controls.Decorator.MeasureOverride(大小约束)
在System.Windows.FrameworkElement.MeasureCore(大小availableSize)
在System.Windows.UIElement.Measure(大小在System.Windows.Controls.Primitives.PopupRoot.MeasureOverride(大小约束)
在System.Windows.FrameworkElement.MeasureCore(大小availableSize)
在System.Windows.UIElement.Measure (Size availableSize)
在System.Windows.Interop.HwndSource.SetLayoutSize()
在System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value)
在System.Windows.Controls.Primitives .Popup.SetRootVisualToPopupRoot()
在Sy处System.Windows.Controls.Primitives.Popup.CreateWindow(Boolean asyncCall)
stem.Windows.Controls.Primitives.Popup.OnIsOpenChanged(DependencyObject d,DependencyPropertyChangedEventArgs e)
在System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)

在System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
在System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex,DependencyProperty dp,PropertyMetadata元数据,EffectiveValueEntry oldEntry,EffectiveValueEntry& amp; newEntry,位于System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp,对象值,PropertyMetadata元数据,布尔值coerceWithDeferredReference,OperationType操作类型,布尔值isInternal)
在System.Windows.DependencyObject中.在System.Windows.Data.BindingOperations.SetBinding(DependencyObject目标,DependencyProperty dp,BindingBase绑定)处的SetValue(DependencyProperty dp,对象值)
在System.Windows.Controls.Primitives.Popup.CreateRootPopup(Popup在System.Windows.Controls.ContextMenu.OnIsOpenChanged(DependencyObject d,DependencyPropertyChangedEventArgs e)处弹出弹出窗口,UIElement子)
在System.Windows.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)处
.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
在System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropert yChangedEventArgs args)
,位于System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex,DependencyProperty dp,PropertyMetadata元数据,EffectiveValueEntry oldEntry,EffectiveValueEntry& newEntry,位于System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp,对象值,PropertyMetadata元数据,布尔值coerceWithDeferredReference,OperationType操作类型,布尔值isInternal)
在System.Windows.DependencyObject中. System.Windows.Documents.TextEditorContextMenu.OnContextMenuOpening(Object sender,ContextMenuEventArgs e)处的SetValue(DependencyProperty dp,Object value)
在System.Windows.Controls.Primitives.TextBoxBase.OnContextMenuOpening(ContextMenuEventArgs e)处
br/>在System.Windows.RoutedEventArgs.InvokeHandler(委托处理程序,对象目标)上
在System.Windows.EventRoute.InvokeHandlersImpl(对象源,RoutedEventArgs args,布尔reRaised) .RaiseEventImpl(DependencyObject sender,RoutedEventArgs args)
在System.Windows.UIElement.RaiseEvent(RoutedEventArgs args,布尔值受信任)
在System.Wind ows.Controls.PopupControlService.RaiseContextMenuOpeningEvent(IInputElement源,Double x,Double y,Boolean userInitiated)
在System.Windows.Controls.PopupControlService.ProcessMouseUp(Object sender,MouseButtonEventArgs e)
在System.Windows. Controls.PopupControlService.OnPostProcessInput(Object sender,ProcessInputEventArgs e)
在System.Windows.Input.InputManager.ProcessStagingArea()
在System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
在System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
上在System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd,InputMode模式,Int32时间戳,RawMouseActions操作,Int32 x,Int32 y,Int32滚轮)
在System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd,Int32 msg,IntPtr wParam,IntPtr lParam,Boolean&已处理) msg,IntPtr wParam,IntPtr lParam,布尔值和已处理)
在MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
在System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate回调,对象参数,布尔值isSingleParameter)
在System.Windows.Threading.ExceptionWrapper.TryCatchWhen(对象源,委托回调,对象args,布尔值isSingleParameter,委托catchHandler)
在System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority优先级, MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd,Int32 msg,IntPtr wParam,IntPtr lParam)
的TimeSpan超时,委托方法,对象args,布尔值isSingleParameter)
MSG& msg)
在System.Windows.Threading.D ispatcher.TranslateAndDispatchMessage(MSG& msg)
在System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
在System.Windows.Application.RunInternal(Window window)
在C中的Test.App.Main() :\ Work \ Projects \ Misc \ Repository \ Projects \ Forms \ Test \ obj \ Debug \ App.g.cs:line 0
在System.AppDomain._nExecuteAssembly(Assembly assembly,String [] args)
在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
上在System.Threading.ExecutionContext.Run(ExecutionContext执行上下文,ContextCallback回调,对象状态) /em>

Everything works fine, but if I right click on the TextBox in the run-time I immediately get the following exception from PresentationFramework :

Message: "'System.Windows.Data.MultiBindingExpression' value cannot be assigned to property 'Visibility' of object 'System.Windows.Controls.Primitives.RepeatButton'. Cannot find non-neutral culture related to 'und'.  Error at object 'System.Windows.Data.MultiBinding'."

Stack:
   at System.Windows.Markup.XamlParseException.ThrowException(String message, Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri, XamlObjectIds currentXamlObjectIds, XamlObjectIds contextXamlObjectIds, Type objectType)
   at System.Windows.Markup.XamlParseException.ThrowException(ParserContext parserContext, Int32 lineNumber, Int32 linePosition, String message, Exception innerException)
   at System.Windows.Markup.BamlRecordReader.SetDependencyComplexProperty(Object currentTarget, BamlAttributeInfoRecord attribInfo, Object o)
   at System.Windows.Markup.BamlRecordReader.SetPropertyValueToParent(Boolean fromStartTag, Boolean& isMarkupExtension)
   at System.Windows.Markup.BamlRecordReader.ReadElementEndRecord(Boolean fromNestedBamlRecordReader)
   at System.Windows.Markup.BamlRecordReader.ReadRecord(BamlRecord bamlRecord)
   at System.Windows.StyleHelper.LoadOptimizedTemplateContent(DependencyObject container, ParserContext parserContext, OptimizedTemplateContent optimizedTemplateContent, FrameworkTemplate frameworkTemplate, IComponentConnector componentConnector, IStyleConnector styleConnector, List`1 affectedChildren, UncommonField`1 templatedNonFeChildrenField)
   at System.Windows.FrameworkTemplate.LoadContent(DependencyObject container, List`1 affectedChildren, UncommonField`1 templatedNonFeChildrenField)
   at System.Windows.StyleHelper.ApplyTemplateContent(UncommonField`1 dataField, DependencyObject container, FrameworkElementFactory templateRoot, Int32 lastChildIndex, HybridDictionary childIndexFromChildID, FrameworkTemplate frameworkTemplate)
   at System.Windows.FrameworkTemplate.ApplyTemplateContent(UncommonField`1 templateDataField, FrameworkElement container)
   at System.Windows.FrameworkElement.ApplyTemplate()
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Border.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Decorator.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Control.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Decorator.MeasureOverride(Size constraint)
   at System.Windows.Documents.AdornerDecorator.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Decorator.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Primitives.PopupRoot.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Interop.HwndSource.SetLayoutSize()
   at System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value)
   at System.Windows.Controls.Primitives.Popup.SetRootVisualToPopupRoot()
   at System.Windows.Controls.Primitives.Popup.CreateWindow(Boolean asyncCall)
   at System.Windows.Controls.Primitives.Popup.OnIsOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, OperationType operationType)
   at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, OperationType operationType, Boolean isInternal)
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at System.Windows.Data.BindingOperations.SetBinding(DependencyObject target, DependencyProperty dp, BindingBase binding)
   at System.Windows.Controls.Primitives.Popup.CreateRootPopup(Popup popup, UIElement child)
   at System.Windows.Controls.ContextMenu.OnIsOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, OperationType operationType)
   at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, OperationType operationType, Boolean isInternal)
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at System.Windows.Documents.TextEditorContextMenu.OnContextMenuOpening(Object sender, ContextMenuEventArgs e)
   at System.Windows.Controls.Primitives.TextBoxBase.OnContextMenuOpening(ContextMenuEventArgs e)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   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 args, Boolean trusted)
   at System.Windows.Controls.PopupControlService.RaiseContextMenuOpeningEvent(IInputElement source, Double x, Double y, Boolean userInitiated)
   at System.Windows.Controls.PopupControlService.ProcessMouseUp(Object sender, MouseButtonEventArgs e)
   at System.Windows.Controls.PopupControlService.OnPostProcessInput(Object sender, ProcessInputEventArgs e)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
   at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
   at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.TranslateAndDispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Application.RunInternal(Window window)
   at Test.App.Main() in C:\Work\Projects\Misc\Repository\Projects\Forms\Test\obj\Debug\App.g.cs:line 0
   at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

推荐答案

其他发现:问题似乎与TextBox控件的上下文菜单有关.如果我添加以下代码
Additional findings: it seems like the problem has something to do with the Context Menu of the TextBox control. If I add the following code
tb.ContextMenu = null;

右键单击仅显示基础DocumentViewer的上下文菜单,不会引发异常.但是,TextBox的ContextMenu仍未显示.

Right-click just shows the context menu of the underlying DocumentViewer and doesn't fire exception. However, ContextMenu of the TextBox is still not shown.


这篇关于在DocumentViewer中右键单击TextBox时发生异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆