C# 弹出:使用文本框IsKeyboardFocused=true数据触发器打开弹出窗口,使用StaysOpen=";关闭弹出窗口;假“;,导致弹出窗口不显示

C# 弹出:使用文本框IsKeyboardFocused=true数据触发器打开弹出窗口,使用StaysOpen=";关闭弹出窗口;假“;,导致弹出窗口不显示,c#,wpf,textbox,popup,datatrigger,C#,Wpf,Textbox,Popup,Datatrigger,我试图在文本框获得键盘焦点时打开一个弹出窗口。当用户单击关闭弹出窗口时,我希望弹出窗口关闭 从我所能收集到的信息来看,StaysOpen=“False”在用户单击弹出窗口时关闭弹出窗口。问题是它不能与IsKeyboardFocused=truedatatrigger一起工作,并导致弹出窗口根本不显示。如果我删除StaysOpen属性,弹出窗口将显示,但在单击时关闭(即使我没有指定关闭事件的代码) 这是我的密码。非常感谢您的帮助,谢谢 <TextBox x:Name="Search

我试图在文本框获得键盘焦点时打开一个弹出窗口。当用户单击关闭弹出窗口时,我希望弹出窗口关闭

从我所能收集到的信息来看,
StaysOpen=“False”
在用户单击弹出窗口时关闭弹出窗口。问题是它不能与
IsKeyboardFocused=true
datatrigger一起工作,并导致弹出窗口根本不显示。如果我删除
StaysOpen
属性,弹出窗口将显示,但在单击时关闭(即使我没有指定关闭事件的代码)

这是我的密码。非常感谢您的帮助,谢谢

    <TextBox x:Name="SearchTextBox" 
             Height="26" 
             Width="165"
             TextWrapping="Wrap" 
             Text="Example">
    </TextBox>
    <Popup
           Placement="Bottom"
           PlacementTarget="{Binding ElementName=SearchTextBox}"
           Height="200"
           Width="100"
           StaysOpen="False"> <!-- If StaysOpen property is removed, popup displays!!! -->
        <Popup.Style>
            <Style TargetType="{x:Type Popup}">
                <Setter Property="IsOpen" Value="False"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding ElementName=SearchTextBox, Path=IsKeyboardFocused}"
                                 Value="true">
                        <Setter Property="IsOpen" Value="True"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Popup.Style>
    </Popup>