XAMLまたはコードを介してファイルメニューのMenuItemにApplicationCommandsコマンドを追加すると、メニューを開くと、アプリケーションがスタックオーバーフローでクラッシュし、問題の詳細がまったくわかりません。コマンドを削除すると、問題も解消されます。どのApplicationCommandを使用するかは関係ありません。
コールスタックの一部:
- WindowsBase.dll!MS.Utility.ArrayItemList.ArrayItemList(int size)+0x20バイト
- WindowsBase.dll!MS.Utility.FrugalStructList.Capacity.set(int value)+0x6aバイト
- WindowsBase.dll!MS.Utility.FrugalStructList.FrugalStructList(int size)+0x9バイト
- PresentationCore.dll!System.Windows.EventRoute.EventRoute(System.Windows.RoutedEvent routedEvent)+0x35バイト
- PresentationCore.dll!System.Windows.EventRouteFactory.FetchObject(System.Windows.RoutedEvent routedEvent)+0x31バイト
- PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender = {System.Windows.Controls.RichTextBox}、System.Windows.RoutedEventArgs args = {System.Windows.Input.CanExecuteRoutedEventArgs})+0x3fバイト
- PresentationCore.dll!System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs args = {System.Windows.Input.CanExecuteRoutedEventArgs}、bool trusted)+0x35バイト
- PresentationCore.dll!System.Windows.Input.RoutedCommand.CriticalCanExecuteWrapper(オブジェクトパラメーター、System.Windows.IInputElementターゲット、boolトラステッド、System.Windows.Input.CanExecuteRoutedEventArgs args)+ 0x80バイト
PresentationCore.dll!System.Windows.Input.RoutedCommand .CanExecuteImpl(object parameter = null、System.Windows.IInputElement target = {System.Windows.Controls.RichTextBox}、bool trusted = false、out bool continueRouting = false)+0x70バイト - PresentationCore.dll!System.Windows.Input.RoutedCommand.CriticalCanExecute(オブジェクトパラメーター、System.Windows.IInputElementターゲット、boolトラステッド、out bool continueRouting)+0x3aバイト
- PresentationCore.dll!System.Windows.Input.CommandManager.TransferEvent(System.Windows.IInputElement newSource、System.Windows.Input.CanExecuteRoutedEventArgs e = {System.Windows.Input.CanExecuteRoutedEventArgs})+0x52バイト
- PresentationCore.dll!System.Windows.Input.CommandManager.OnCanExecute(object sender、System.Windows.Input.CanExecuteRoutedEventArgs e)+ 0x8c bytes
PresentationCore.dll!System.Windows.UIElement.OnCanExecuteThunk(object sender、System.Windows.Input。 CanExecuteRoutedEventArgs e)+0x44バイト - PresentationCore.dll!System.Windows.Input.CanExecuteRoutedEventArgs.InvokeEventHandler(System.Delegate genericHandler、オブジェクトターゲット)+ 0x41バイト
PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegateハンドラー、オブジェクトターゲット)+0x27バイトPresentationCore。 dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(object target、System.Windows.RoutedEventArgs routedEventArgs)+ 0x3e bytes
PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source = {System.Windows.Controls.RichTextBox}、System。 Windows.RoutedEventArgs args = {System.Windows.Input.CanExecuteRoutedEventArgs}、bool reRaised = false)+0x1bfバイト - PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender = {System.Windows.Controls.RichTextBox}、System.Windows.RoutedEventArgs args =+0x79バイト
- PresentationCore.dll!System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs args = {System.Windows.Input.CanExecuteRoutedEventArgs}、bool trusted)+0x35バイト
- PresentationCore.dll!System.Windows.Input.RoutedCommand.CriticalCanExecuteWrapper(オブジェクトパラメーター、System.Windows.IInputElementターゲット、boolトラステッド、System.Windows.Input.CanExecuteRoutedEventArgs args)+0x80バイト
アプリケーションが無限ループに陥っているようです。これは私のせいですか(そして何が間違っているのですか)、それとも.NET 3.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から派生したコントロールのコンストラクターに追加されます。