Lorsque j'ajoute une commande ApplicationCommands à un MenuItem dans mon menu fichier, peu importe via XAML ou via le code, lorsque j'ouvre le menu, l'application se bloque dans un débordement de pile, sans aucun des détails sur le problème. Lorsque je supprime la commande, le problème disparaît également. Peu importe quelle ApplicationCommand j'utilise.Dépassement de pile lors de l'ouverture du menu avec ApplicationCommands en C#
Une partie de la pile d'appel:
- WindowsBase.dll MS.Utility.ArrayItemList.ArrayItemList (int taille ) + 0x20 octets
- WindowsBase.dll MS.Utility.FrugalStructList.Capacity!. set (int valeur) + 0x6A octets
- WindowsBase.dll! MS.Utility.FrugalStructList.FrugalStructList (int taille) + 0x9 octets
- PresentationCore.dll! System.Windows.EventRoute.EventRoute (System.Windows. Ro utedEvent RoutedEvent) + 0x35 octets
- PresentationCore.dll! System.Windows.EventRouteFactory.FetchObject (System.Windows.RoutedEvent RoutedEvent) + 0x31 octets
- PresentationCore.dll! System.Windows.UIElement.RaiseEventImpl (système. Windows.DependencyObject expéditeur = { System.Windows.Controls.RichTextBox}, System.Windows.RoutedEventArgs args = { System.Windows.Input.CanExecuteRoutedEventArgs}) + 0x3f octets
- PresentationCore.dll! System.Windows. UIElement.RaiseEvent (System.Windows.RoutedEventArgs args = {} System.Windows.Input.CanExecuteRoutedEventArgs, bool confiance) + 0x35 octets
- PresentationCore.dll! System.Windows.Input.RoutedCommand.CriticalCanExecuteWrapper (objet paramètre , cible System.Windows.IInputElement, bool confiance , System.Windows.Input.CanExecuteRoutedEventArgs args) + 0x80 octets
PresentationCore.dll! System.Windows.Input.RoutedCommand.CanExecuteImpl (objet paramètre = nULL, cible System.Windows.IInputElement = {System.Windows .Controls.RichTextBox}, bool trust = false, out bool co ntinueRouting = false) + 0x70 octets - PresentationCore.dll! System.Windows.Input.RoutedCommand.CriticalCanExecute (objet paramètre , cible System.Windows.IInputElement, bool confiance, sur bool continueRouting) + 0x3a octets
- PresentationCore.dll! System.Windows.Input.CommandManager.TransferEvent (System.Windows.IInputElement Newsource, System.Windows.Input.CanExecuteRoutedEventArgs e = { System.Windows.Input.CanExecuteRoutedEventArgs}) + 0x52 octets
- PrésentationCor e.dll! System.Windows.Input.CommandManager.OnCanExecute (sender objet , System.Windows.Input.CanExecuteRoutedEventArgs e) + 0x8c octets
PresentationCore.dll! System.Windows.UIElement.OnCanExecuteThunk (objet expéditeur, System.Windows.Input.CanExecuteRoutedEventArgs e) + 0x44 octets - PresentationCore.dll! System.Windows.Input.CanExecuteRoutedEventArgs.InvokeEventHandler (System.Delegate GenericHandler, objet cible) + 0x41 octets
PresentationCore.dll! System.Windows.RoutedEventArgs.InvokeHandler (gestionnaire System.Delegate , cible de l'objet) + 0x27 octets PresentationCore.dll! System.Windows.RoutedEventHandlerInfo.InvokeHandler (objectif de l'objet , System.Windows.RoutedEventArgs RoutedEventArgs) + 0x3E octets
système PresentationCore.dll!. Windows.EventRoute.InvokeHandlersImpl (objet source = { System.Windows.Controls.RichTextBox}, System.Windows.RoutedEventArgs args = { System.Windows.Input.CanExecuteRoutedEventArgs}, bool = false relance) + 0x1bf octets - PresentationCore.dll système! .Windows.UIElement.RaiseEventImpl (System.Windows.DependencyObject expéditeur = { System.Windows.Controls.RichTextBox}, System.Windows.RoutedEventArgs args = + 0x79 octets
- PresentationCore.dll! System.Windows.UIElement. RaiseEvent (System.Windows.RoutedEventArgs args = {System.Windows.Input.CanExecuteRoutedEventArgs}, bool confiance) + 0x35 octets
- PresentationCore.dll! System.Windows.Input.RoutedCommand.CriticalCanExecuteWrapper (objet paramètre, cible System.Windows.IInputElement, bool confiance, System.Windows.Input.CanExecuteRoutedEventArgs args) + 0x80 octets
Il semble que l'application soit bloquée dans une boucle sans fin. Est-ce ma faute (et qu'est-ce que je fais mal) ou un bug dans .NET 3.5?
J'utilise ce code:
MenuItem mi = new MenuItem();
mi.Command = ApplicationCommands.Open;
FileMenu.Items.Add(mi);
Peu importe wheter je crée le ligneMenu par code ou en XAML, et comme je l'ai dit le réglage de la commande n'a pas d'importance où. Le problème se produit également lors de l'utilisation de MediaCommands, donc je suppose que pour toutes les commandes en général.
Le code 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);
Le RichTextBox est ajouté dans le constructeur d'une commande qui est dérivé de TabItem.
Où se trouve ce code? Quelle est la méthode? – Yohnny
Le code est dans le constructeur de la fenêtre. Ce n'est pas grave si je mets la commande avant que le MenuItem soit ajouté au Menu ou après, j'ai essayé les deux. – Ruud
Pour moi, il est étrange de voir System.Windows.Controls.RichTextBox comme expéditeur dans cette trace de la pile. –