質問者
WindowsFormsHost内のWinFormコントロールにフォーカスを設定した状態でショートカットキーでモーダルウィンドウを表示した際にウィンドウ内のWPFテキストボックスの文字入力が正常にできなくなる

質問
-
長々としたタイトルですが、発生している現象手順・ソースを下記に記載します。
Window1(ホスト)
XAML------------------
<Window x:Class="ConverterTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:WinControls="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
>
<my:WindowsFormsHost xmlns:my="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration">
<WinControls:TextBox/>
</my:WindowsFormsHost>
</Window>
------------------------------------------------------
using System.Windows;
using System.Windows.Input;
namespace ConverterTest
{
/// <summary>
/// Window1.xaml の相互作用ロジック
/// </summary>
public partial class Window1
{
public static RoutedCommand cmdShowDialog = new RoutedCommand("cmdShowDialog", typeof (Window),
new InputGestureCollection {new KeyGesture(Key.F2)});
public Window1()
{
InitializeComponent();
this.CommandBindings.Add(new CommandBinding(cmdShowDialog, OnShowDialog));
}
private void OnShowDialog(object sender, ExecutedRoutedEventArgs e)
{
Window2 window2 = new Window2();
window2.Owner = this;
window2.ShowDialog();
}
}
}
Window2(サブウィンドウ)
XAML------------------
<Window x:Class="ConverterTest.Window2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Dialog" Height="300" Width="300">
<TextBox/>
</Window>
--------------------------------
Window1からRoutedCommandでWindow2を表示するプログラムですが、
Window1内のTextBox(WinForm)にフォーカスを設定しショートカットキーのF2を押下しWindow2をモーダル表示した場合に
Window2内のTextBox(WPF)でIME入力モードを'ひらがな'にし'a'キーを押下すると、ひらがなで「あ」の変換待ち状態となるのはずですが、「あa」となってしまいます。
Buttonコントロールにコマンドを設定し、ボタンから実行した場合では上記現象は発生していません。
また、WinFormコントロール以外にフォーカスがある場合・モードレスウィンドウ・XP環境でも上記現象は発生しません。
原因が分からず困っております。対処方法等ございましたら教えてください。
環境:Visual Studio 2008 SP1 OS:Vista SP1
すべての返信
-
うちの環境でも再現しました。
OSとVSは一緒です。
メッセージループがWPFとWindowsフォームとで別?だから変な動きをしてしまうんですかね…
↓のURLの内容がそれっぽいかなと思ったのですが、私がやった感じだと、うまくいきませんでした。
http://msdn.microsoft.com/ja-jp/library/ms742474(VS.80).aspx
最終的に、以下のやり方で正常に動くようになったのですが、何故動くようになったのかわかりません…
ここら辺詳しいかたの解説があるのを待ってみます(^^;
OnShowWindowメソッドを以下の内容に書き換えるAction action = () => { var win = new Window2(); win.Owner = this; win.ShowDialog(); }; Dispatcher.CurrentDispatcher.BeginInvoke(action);
かずき Blog:http://blogs.wankuma.com/kazuki/