0

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から派生したコントロールのコンストラクターに追加されます。

4

2 に答える 2

0

はい、これはあなたのせいであり、3.5のバグではありません(ねえ、あなたは尋ねました)。今あなたのバグを見つけるために...

スタックトレースから、CanExecuteイベントが多数あり、それらはRichTextBoxに関連付けられているようです。コードにCanExecuteロジックがありますか?正直なところ、効果的に支援するには、より多くのコードが必要です。

また、無限ループとスタックオーバーフローは異なります。プログラムがSO例外で爆発したことはありますか、それとも永久に実行され続けますか?

于 2009-07-09T20:41:13.090 に答える
0

問題が見つかりました。RichTextBox をフォーカス グループに追加していました。私はそれを削除しましたが、今は動作します。ただし、起動時にRichTextBoxでキーボードフォーカスを取得できません。(Keyboard.Focus(sb)、sb.Focus()、sb.Document.Focus()、Keyboard.Focus(sb.Document)、FocusManager.SetFocusedElement(this、sb)などを試しました...

于 2009-07-10T07:43:38.523 に答える