我已经成功创建了一个ComboBox,其ItemPresenter是使用选定项行为实现的TreeView。
<Popup x:Name="PART_Popup" AllowsTransparency="true" Focusable="false" IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
<Microsoft_Windows_Themes:SystemDropShadowChrome x:Name="Shdw" Color="Transparent" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{TemplateBinding ActualWidth}">
<Border x:Name="DropDownBorder" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
<ScrollViewer>
<TreeView x:Name="PART_TreeView" ItemsSource="{TemplateBinding ItemsSource}">
<Interactivity:Interaction.Behaviors>
<ComboTreeView:BindableSelectedItemBehaviour SelectedItem="{Binding RelativeSource={RelativeSource AncestorType={x:Type ComboBox} }, Path=SelectedItem, Mode=TwoWay}" />
</Interactivity:Interaction.Behaviors>
</TreeView>
</ScrollViewer>
</Border>
</Microsoft_Windows_Themes:SystemDropShadowChrome>
</Popup>
在树形视图中选择一个项可以正确设置组合框的选定项。我不确定如何在选择后关闭弹出窗口。每次都必须选择并在控件外单击才能让弹出窗口消失。这可以在XAML中完成吗?