1

次の動作が必要です。ウィンドウに入力を開始すると、最初の文字が既に入力された小さなテキストボックスが表示され、テキストを入力して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;

        }
    }
4

2 に答える 2

1

e.Handled =true を追加する必要があるため、Window_KeyDown_1 は発生せず、ポップアップを再度開きます

   private void tbx_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Enter)
        {
            Popup1.IsOpen = false;
            temp = tbx.Text;
            tbx.Text = null;
            e.Handled = true;

        }
    }
于 2013-03-06T11:54:34.290 に答える