可视树中的ComboBox弹出窗口在哪里? [英] Where is ComboBox popup in visual tree?

查看:47
本文介绍了可视树中的ComboBox弹出窗口在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在视觉树的哪里可以找到ComboBox弹出窗口(带有ComboBoxItems的列表)?

Where in the visual tree can I find the ComboBox popup (the list with the ComboBoxItems)?

我已经以编程方式打开了一个ComboBox,在调试器的WPF Tree Visualizer中观看它时,我看到以下内容:

I have programmatically opened a ComboBox and when watching it in the WPF Tree Visualizer in the debugger I see the following:

: ComboBox
  templateRoot : Grid
    PART_Popup : Popup
    toggleButton : ToggleButton
      templateRoot : Border
        splitBorder : Border
          Arrow : Path
    contentPresenter : ContentPresenter
      : TextBlock

我希望看到带有某种项目宿主(StackPanel?)的ScrollViewer,也许在PART_Popup所在的位置,但是什么也没有.

I expected to see a ScrollViewer with some kind of item host (StackPanel?), perhaps where the PART_Popup is, but nothing.

那它在哪里?

推荐答案

PART_Popup确实将StackPanel的ItemsHost设置为True,并由ScrollViewer进行了包装.您可以在> MSDN .

PART_Popup does have StackPanel with ItemsHost set to True and wrapped around by ScrollViewer. You can check out the default template here at MSDN.

它是这样的:

<Popup x:Name="Popup"
       Placement="Bottom"
       IsOpen="{TemplateBinding IsDropDownOpen}"
       AllowsTransparency="True"
       Focusable="False"
       PopupAnimation="Slide">
    <Grid x:Name="DropDown"
          SnapsToDevicePixels="True"
          MinWidth="{TemplateBinding ActualWidth}"
          MaxHeight="{TemplateBinding MaxDropDownHeight}">
      <Border x:Name="DropDownBorder"
              BorderThickness="1">
        <Border.BorderBrush>
          <SolidColorBrush Color="{DynamicResource BorderMediumColor}" />
        </Border.BorderBrush>
        <Border.Background>
          <SolidColorBrush Color="{DynamicResource ControlLightColor}" />
        </Border.Background>
      </Border>
      <ScrollViewer Margin="4,6,4,6"
                    SnapsToDevicePixels="True">
        <StackPanel IsItemsHost="True"
                    KeyboardNavigation.DirectionalNavigation="Contained" />
      </ScrollViewer>
    </Grid>
</Popup>


更新

PopUp和comboBox不共享同一根.它们属于不同的可视树,这就是为什么在WPF Tree Visualizer中不可见的原因,因为需要打开PopUp才能看到它的可视树.

PopUp and comboBox doesn't share the same root. They belong to different Visual Tree, that's why not visible in WPF Tree Visualizer since PopUp needs to be opened to see it's Visual Tree.

您可以使用 Snoop ,它是WPF间谍工具,还具有以下功能:检查视觉树.从Snoop弹出的快照看起来像这样(Windows 8):

这篇关于可视树中的ComboBox弹出窗口在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆