Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF-FrameworkElement-是否枚举所有中心?_C#_.net_Wpf_Frameworkelement - Fatal编程技术网

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调试工具,适用于与可视化树相关的所有内容

编辑:您的具体问题似乎是时间问题。我猜树还没有完全构造好,您试图访问一个子元素,尽管它还没有创建。等待最上面的元素收到“已加载”事件