Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用C语言中的应用程序命令打开菜单时堆栈溢出_C#_Wpf_Stack Overflow_Command - Fatal编程技术网

C# 使用C语言中的应用程序命令打开菜单时堆栈溢出

C# 使用C语言中的应用程序命令打开菜单时堆栈溢出,c#,wpf,stack-overflow,command,C#,Wpf,Stack Overflow,Command,当我向文件菜单中的菜单项添加ApplicationCommands命令时,无论是通过XAML还是通过代码,当我打开菜单时,应用程序在堆栈溢出中崩溃,完全没有关于问题的详细信息。当我删除该命令时,问题也消失了。我使用哪个应用程序命令并不重要 调用堆栈的一部分: WindowsBase.dll!MS.Utility.ArrayItemList.ArrayItemListint 大小+0x20字节 WindowsBase.dll!MS.Utility.FrugalStructList.Capacity

当我向文件菜单中的菜单项添加ApplicationCommands命令时,无论是通过XAML还是通过代码,当我打开菜单时,应用程序在堆栈溢出中崩溃,完全没有关于问题的详细信息。当我删除该命令时,问题也消失了。我使用哪个应用程序命令并不重要

调用堆栈的一部分:

WindowsBase.dll!MS.Utility.ArrayItemList.ArrayItemListint 大小+0x20字节 WindowsBase.dll!MS.Utility.FrugalStructList.Capacity.setint 值+0x6a字节 WindowsBase.dll!MS.Utility.FrugalStructList.FrugalStructListint 大小+0x9字节 PresentationCore.dll!System.Windows.EventRoute.EventRouteSystem.Windows.RouteEvent routedEvent+0x35字节 PresentationCore.dll!System.Windows.EventRouteFactory.FetchObjectSystem.Windows.RouteEvent RouteEvent+0x31字节 PresentationCore.dll!System.Windows.UIElement.RaiseEventImplSystem.Windows.DependencyObject 寄件人= {System.Windows.Controls.RichTextBox}, System.Windows.RoutedEventArgs参数= {System.Windows.Input.canExecuteRouteEventArgs}+0x3f字节 PresentationCore.dll!System.Windows.UIElement.RaiseEventSystem.Windows.RoutedEventTargets args= {System.Windows.Input.canExecuteRouteEventArgs}, bool可信+0x35字节 PresentationCore.dll!System.Windows.Input.RoutedCommand.CriticalCanExecuteWrapperobject 参数 System.Windows.IIInputElement目标, 布尔相信, System.Windows.Input.CanExecuteRouteEventArgs args+0x80字节 PresentationCore.dll!System.Windows.Input.RoutedCommand.CanExecuteImplobject 参数=null, System.Windows.IIInputElement目标= {System.Windows.Controls.RichTextBox}, bool trusted=false,out bool continueRouting=false+0x70 字节 PresentationCore.dll!System.Windows.Input.RoutedCommand.CriticalCanExecuteobject 参数 System.Windows.IIInputElement目标, 布尔信任,出局布尔 连续运算+0x3a字节 PresentationCore.dll!System.Windows.Input.CommandManager.TransferEventSystem.Windows.IIInputElement 新闻来源, System.Windows.Input.CanExecuteRouteEventArgs e= {System.Windows.Input.canExecuteRouteEventArgs}+0x52字节 PresentationCore.dll!System.Windows.Input.CommandManager.OnCanExecuteobject 发件人, System.Windows.Input.CanExecuteRouteEventArgs e+0x8c字节 PresentationCore.dll!System.Windows.UIElement.OnCanExecuteThunkobject 发件人, System.Windows.Input.CanExecuteRouteEventArgs e+0x44字节 PresentationCore.dll!System.Windows.Input.CanExecuteRouteEventArgs.InvokeeEventHandlerSystem.Delegate genericHandler,对象目标+0x41 字节 PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandlerSystem.Delegate 处理程序,对象目标+0x27字节 PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandlerobject 目标 System.Windows.RoutedEventArgs routedEventArgs+0x3e字节 PresentationCore.dll!System.Windows.EventRoute.InvokeHandlerSimpleObject 来源= {System.Windows.Controls.RichTextBox}, System.Windows.RoutedEventArgs参数= {System.Windows.Input.canExecuteRouteEventArgs}, bool reRaised=false+0x1bf字节 PresentationCore.dll!System.Windows.UIElement.RaiseEventImplSystem.Windows.DependencyObject 寄件人= {System.Windows.Controls.RichTextBox}, System.Windows.RoutedEventArgs args=+0x79字节 PresentationCore.dll!System.Windows.UIElement.RaiseEventSystem.Windows.RoutedEventTargets args= {System.Windows.Input.canExecuteRouteEventArgs}, bool可信+0x35字节 PresentationCore.dll!System.Windows.Input.RoutedCommand.CriticalCanExecuteWrapperobject 参数 System.Windows.IIInputElement目标, 布尔相信, System.Windows.Input.CanExecuteRouteEventArgs args+0x80字节 看起来应用程序陷入了一个无休止的循环中。这是我的错吗?我做错了什么?还是.NET3.5中的错误

我使用以下代码:

MenuItem mi = new MenuItem();
mi.Command = ApplicationCommands.Open;
FileMenu.Items.Add(mi);
无论是通过代码还是在XAML中创建menuItem,都无关紧要,正如我所说,在何处设置命令也无关紧要。使用MediaCommands时也会出现这个问题,所以我想一般情况下所有命令都会出现这个问题

RichTextBox代码:

//configure richtextbox
sb = new RichTextBox();
sb.Margin = new Thickness(-3);
sb.BorderThickness = new Thickness(0);
sb.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
sb.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
///TODO: get font from preferences.
FontFamilyConverter ffc = new FontFamilyConverter();
sb.FontFamily = (FontFamily)ffc.ConvertFromString("Lucida Sans Unicode");
sb.FontSize = 13;
sb.AcceptsReturn = true; sb.AcceptsTab = true;
sb.AllowDrop = true; sb.IsDocumentEnabled = false;
sb.Padding = new Thickness(5);

//markup styles
Style s = new Style(typeof(Paragraph));
s.Setters.Add(new Setter(Paragraph.MarginProperty, new Thickness(0)));
sb.Resources.Add(typeof(Paragraph), s);

this.AddChild(sb);

RichTextBox被添加到从TabItem派生的控件的构造函数中。

是的,这是你的错,而不是3.5中的错误嘿,你问。现在要找到你的错误

从堆栈跟踪来看,有很多CanExecute事件,它们似乎与RichTextBox关联。您的代码中有任何CanExecute逻辑吗?老实说,我们需要更多的代码来有效地提供帮助


另外,无止境循环和堆栈溢出是不同的。您的程序是否曾经因为如此异常而崩溃,还是一直在运行?

我发现了这个问题。我正在将我的RichTextBox添加到焦点小组。我移除了它,现在它可以工作了。尽管在启动时我仍然无法在RichTextBox中获得键盘焦点。试过键盘。Focussb,sb。Focus,sb。Document。Focus,Keyboard。Focussb。Document,FocusManager。SetFocuseDelete这个,sb,等等…

这个在哪里
代码定位?它在什么方法中?代码在窗口的构造函数中。无论我是在菜单项添加到菜单之前还是之后设置命令,我都尝试了这两种方法。对于我来说,在堆栈跟踪中看到System.Windows.Controls.RichTextBox作为发送者是很奇怪的。我的窗口中确实有一个RichTextBox,这是否相关?不,只是StackOverflow错误。我的代码中没有任何CanExecute逻辑。我在我的问题中添加了RichTextbox代码。你必须在其中进行某种递归/循环调用。您是否有任何事件处理程序执行一些不应该执行的逻辑?我做了一些其他测试,结果表明并非所有命令都返回错误。。。应用程序命令。撤消不起作用。