Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 打开文本框焦点上的WPF弹出窗口_C#_Wpf_Wpf Controls - Fatal编程技术网

C# 打开文本框焦点上的WPF弹出窗口

C# 打开文本框焦点上的WPF弹出窗口,c#,wpf,wpf-controls,C#,Wpf,Wpf Controls,当焦点在文本框上时,我想打开一个弹出窗口 以下是我编写的代码: <Window x:Class="Testpopup.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"

当焦点在文本框上时,我想打开一个弹出窗口 以下是我编写的代码:

<Window x:Class="Testpopup.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <StackPanel>
        <TextBox  x:Name="text" GotKeyboardFocus="text_GotKeyboardFocus" />
        <Button Click="Button_Click"  Content="but"/>
        <Popup x:Name="popup" Width="100" Height="100" PlacementTarget="{Binding ElementName=text}"
            StaysOpen="False">
            <Grid>
                <StackPanel>
                    <DatePicker />
                    <TextBox />
                </StackPanel>
            </Grid>
        </Popup>

    </StackPanel>
</Grid>
如果我点击按钮,一切正常 如果单击文本框,弹出窗口将打开和关闭

如果我删除StaysOpen=“False”,弹出窗口将打开但从不关闭

我试图在打开弹出窗口之前将焦点设置在弹出窗口上,但它不起作用

你知道吗

非常感谢,,
Nidal。

将以下绑定添加到弹出声明中:

StaysOpen="{Binding ElementName=text,Path=IsKeyboardFocused}"
这应该可以解决问题。

您尝试过使用触发器吗?
StaysOpen="{Binding ElementName=text,Path=IsKeyboardFocused}"