次の動作が必要です。ウィンドウに入力を開始すると、最初の文字が既に入力された小さなテキストボックスが表示され、テキストを入力してEnterキーを押すと、そのウィンドウに再度入力するまでテキストボックスが消えます。問題は、Popup1.IsOpen = false
テキストボックスをウィンドウに残すように設定した場合です。
<Window x:Class="Beta.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" KeyDown="Window_KeyDown_1">
<Grid>
<Popup Name="Popup1" IsEnabled="True" IsOpen="False" VerticalOffset="-200" HorizontalOffset="50">
<TextBox Name="tbx" Width="50" KeyDown="tbx_KeyDown" />
</Popup>
</Grid>
</Window>
string temp;
private void Window_KeyDown_1(object sender, KeyEventArgs e)
{
Popup1.IsOpen = true;
tbx.Focus();
}
private void tbx_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
Popup1.IsOpen = false;
temp = tbx.Text;
tbx.Text = null;
}
}