2017-12-18 1 views
0

OnScreenKeyboard를 클릭하면 TextBox UserControl을 볼 수 있습니다. OnScreenKeyboard를 시작하는 내 텍스트 상자의 코드 숨김은 다음과 같습니다Selfmade OnScreenKeyboard에 반응 할 두 번째 탭이 필요합니다.

private void TextBoxText_PreviewMouseDown(object sender, MouseButtonEventArgs e) 
     { 
      TextBox textbox = sender as TextBox; 
      US_Keyboard keyboardWindow = new US_Keyboard(textbox, Window.GetWindow(this)); 
      if (keyboardWindow.ShowDialog() == true) 
       textbox.Text = keyboardWindow.InputSource.Text; 
     } 

OnScreenKeyboard이 창에서 상속 부분 클래스입니다. OnScreenKeyboard의 생성자는 다음과 같습니다

public US_Keyboard(TextBox owner, Window wndOwner) 
    { 
     InitializeComponent(); 
     this.Owner = wndOwner; 
     this.DataContext = this; 

     //Delete text in textbox 
     if (InputSource.Text.Length > 0) 
     { 
      OldTextBoxValue = InputSource.Text; 
      InputSource.Text = ""; 
     } 

     //Set caret to start point of textbox 
     AdornerLayer layer = AdornerLayer.GetAdornerLayer(owner); 
     CaretAdorner adorner = new CaretAdorner(owner); 
     adorner.OffsetX = _CaretOffsetXDefault; 
     layer.Add(adorner); 
     _adorner = adorner; 
     _layer = layer; 

     SetKeyboardSize(); 
     SetKeyboardPosition(); 
    } 

지금까지 모든 것을 한 가지를 제외하고 잘 작동 다음 OnScreenKeyboard - 윈도우가 표시됩니다 후에는 반응하는 두 번째 탭이 필요합니다. 초점이 없으므로 초점을 맞추려면 클릭 한 번만 있으면됩니다. 이 문제를 어떻게 해결할 수 있습니까?

나는 이미 생성자에 다음을 시도했지만 도움이되지 않습니다

this.Focus(); 
+0

가능한 [WPF 창 설정 포커스] (https://stackoverflow.com/questions/6395645/wpf-window-set-focus) – Mahmoud

+0

같은 중복 될 수도 있지만 솔루션은 나를 위해 작동하지 않습니다. –

+1

나는 포커스를 필요로하는 것에 대해 더 걱정이된다. 입력 키보드가 주 입력 포커스가 입력을받는 다른 응용 프로그램에 머무르는 동안 마우스 클릭을 받아 화면 키보드가 이상적으로 작동하지 않아야합니까? – grek40

답변

0

당신은 Win32 API를 사용하여 고려할 수 있습니다 : 당신이 창을 집중하고 싶은 경우

using System; 
using System.Windows; 
using System.Windows.Interop; 
using System.Runtime.InteropServices; 

namespace YourSolution 
{ 
    static class WindowExtensions 
    { 
     [DllImport("User32.dll")] 
     internal static extern bool SetForegroundWindow(IntPtr hWnd); 

     public static void SetFocus(this Window window) 
     { 
      var handle = new WindowInteropHelper(window).Handle; 
      SetForegroundWindow(handle); 
     } 
    } 
} 

, window.SetFocus();를 사용 .
참고 : SetFocus으로 전화하기 전에 초점을 맞추려는 창을로드해야합니다.

+0

왜 win32 API 사용을 고려해야합니까? –

+0

@jimmmmyjooo 왜냐하면 당신은'Focus' 방법이 효과가 없다고했기 때문입니다. 이 API는별로 복잡하지 않습니다. 시도하지 않으시겠습니까? –

+0

win32 api를 사용하면 도움이되지 않습니다 –

관련 문제