C# WPF-FrameworkElement-是否枚举所有中心?
我有一个C# WPF-FrameworkElement-是否枚举所有中心?,c#,.net,wpf,frameworkelement,C#,.net,Wpf,Frameworkelement,我有一个框架元素(实际上是一个切换按钮),它的内容中有一个弹出窗口 我是这样访问它的: ToggleButton button = (ToggleButton)sender; Popup popup = (Popup)button.FindName("popSelectIteration"); 通常这很好用。但有时弹出窗口是空的 我正在试图找到一种调试方法。有没有办法列举FindName能找到的所有“东西” 作为背景,以下是如何在ToggleButton中定义我的弹出窗口: <Togg
框架元素
(实际上是一个切换按钮
),它的内容中有一个弹出窗口
我是这样访问它的:
ToggleButton button = (ToggleButton)sender;
Popup popup = (Popup)button.FindName("popSelectIteration");
通常这很好用。但有时弹出窗口是空的
我正在试图找到一种调试方法。有没有办法列举FindName能找到的所有“东西”
作为背景,以下是如何在ToggleButton中定义我的弹出窗口:
<ToggleButton Grid.Column="1" HorizontalAlignment="Right" Margin="0,2,0,2" Checked="btnFindIterationChecked">
<Grid>
<Popup PlacementTarget="{Binding ElementName=chkIteration}" Name="popSelectIteration" Closed="popSelectIteration_Closed"
AllowsTransparency="True" StaysOpen="False" PopupAnimation="Fade">
<Border BorderBrush="#FF000000" Background="LightBlue" BorderThickness="1,1,1,1" CornerRadius="8,8,8,8" Padding="5">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="300"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Foreground="Black" >Select Destination:</TextBlock>
<ScrollViewer Grid.Row="1" >
<TreeView ItemsSource="{Binding IterationTree}" SelectedItemChanged="TreeView_SelectedItemChanged">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Children}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding PathEnd}" />
</StackPanel>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
</ScrollViewer>
<Button Grid.Row="2" Background="LightBlue" Content="Clear Selection" Click="btnClear_Click"/>
</Grid>
</Border>
</Popup>
</Grid>
</ToggleButton>
选择目的地:
试试看。它是一个伟大的WPF调试工具,适用于与可视化树相关的所有内容
编辑:您的具体问题似乎是时间问题。我猜树还没有完全构造好,您试图访问一个子元素,尽管它还没有创建。等待最上面的元素收到“已加载”事件