首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WPF - FrameworkElement -枚举所有的装饰?

WPF - FrameworkElement -枚举所有的装饰?
EN

Stack Overflow用户
提问于 2010-02-17 23:19:30
回答 1查看 1K关注 0票数 2

我有一个FrameworkElement (实际上是一个ToggleButton),它的内容中包含一个Popup

我是这样访问的:

代码语言:javascript
复制
ToggleButton button = (ToggleButton)sender;
Popup popup = (Popup)button.FindName("popSelectIteration");

通常情况下这个很好。但有时弹出是空的。

我正在试图找到一种方法来调试这个。有没有一种方法可以枚举FindName可以找到的所有“东西”?

作为背景,下面是如何在ToggleButton中定义弹出窗口的:

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-02-17 23:34:44

试试斯诺普。它是一个伟大的WPF调试实用程序,所有与视觉树有关的东西。

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2285196

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档