Je recherche un contrôle en utilisant LogicalTreeHelper.FindLogicalNode
dans un RibbonWindow
. L'élément que je recherche génère l'erreur: La méthode spécifiée n'est pas prise en charge. Si le contrôle Ribbon
est supprimé de XAML ou s'il est déplacé derrière le TextBlock
FindLogicalNode
fonctionne correctement. Quelqu'un at-il une explication?FindLogicalNode échoue lors de la recherche dans RibbonWindow
Voici le XAML:
<RibbonWindow x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication1"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Ribbon Grid.Row="0"/> <!-- if moved behind the TextBox or removed it works -->
<TextBox Name="myTextBox" />
</Grid>
Voici le code derrière:
public partial class MainWindow : RibbonWindow
{
public MainWindow()
{
InitializeComponent();
TextBox textBox = (TextBox)System.Windows.LogicalTreeHelper.FindLogicalNode(this, "myTextBox");
}
}
Merci pour la solution. Avez-vous une idée pourquoi FindLogicalNode échoue? –
Parce que le TextBox est introuvable dans l'arborescence * logical *. – mm8