我有一个FrameworkElement (实际上是一个ToggleButton),它的内容中包含一个Popup。
我是这样访问的:
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>发布于 2010-02-17 23:34:44
试试斯诺普。它是一个伟大的WPF调试实用程序,所有与视觉树有关的东西。
编辑:不过,您的具体问题似乎是时间问题。我猜树还没有完全构建,您尝试访问一个子元素,尽管它还没有创建。等待最上面的元素收到一个“加载”事件。
https://stackoverflow.com/questions/2285196
复制相似问题