2

私はそのコンテンツの中にFrameworkElementaを持っている(本当に)を持っています。ToggleButtonPopup

私はこのようにアクセスします:

ToggleButton button = (ToggleButton)sender;
Popup popup = (Popup)button.FindName("popSelectIteration");

通常、これは正常に機能します。ただし、ポップアップがnullになる場合があります。

これをデバッグする方法を見つけようとしています。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>
4

1 に答える 1

1

スヌープを試してみてください。これは、ビジュアル ツリーに関係するすべてのものに対する優れた WPF デバッグ ユーティリティです。

編集:ただし、特定の問題はタイミングの問題のようです。ツリーがまだ完全に構築されておらず、作成されていない子要素にアクセスしようとしていると思います。一番上の要素が「Loaded」イベントを受け取るまで待ちます。

于 2010-02-17T23:34:44.617 に答える