Q016.ComboBox で InputMethod.IsInputMethodEnabled="False" としても、IME が無効になりません。

A. MSDN フォーラムで質問し、Connect にもフィードバックしましたが、これは ComboBox の仕様みたいです。回避策は、以下のように若干手の込んだ仕掛けが必要です。
まず添付ビヘイビアと拡張メソッドを提供するヘルパクラスを用意します。

using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

public class ComboBoxBehaviors {

    public static readonly DependencyProperty IsInputMethodEnabledProperty =
        DependencyProperty.RegisterAttached("IsInputMethodEnabled", typeof(bool),
        typeof(ComboBoxBehaviors), new UIPropertyMetadata(true, OnIsInputMethodEnabledChanged));

    public static bool GetIsInputMethodEnabled(DependencyObject obj) {
        return (bool)obj.GetValue(IsInputMethodEnabledProperty);
    }

    public static void SetIsInputMethodEnabled(DependencyObject obj, bool value) {
        obj.SetValue(IsInputMethodEnabledProperty, value);
    }

    private static void OnIsInputMethodEnabledChanged
            (DependencyObject obj, DependencyPropertyChangedEventArgs args) {
        var comboBox = obj as ComboBox;
        if (comboBox == null) return;
        comboBox.Loaded +=
            (s, e) => {
                var textBox = comboBox.FindChild(typeof(TextBox), "PART_EditableTextBox");
                if (textBox == null) return;

                textBox.SetValue(InputMethod.IsInputMethodEnabledProperty, args.NewValue);
            };
    }
}

public static class UIChildFinder {

    public static DependencyObject FindChild
            (this DependencyObject reference, Type childType, string childName) {

        DependencyObject foundChild = null;
        if (reference != null) {

            int childrenCount = VisualTreeHelper.GetChildrenCount(reference);
            for (int i = 0; i < childrenCount; i++) {

                var child = VisualTreeHelper.GetChild(reference, i);
                if (child.GetType() != childType) {
                    foundChild = FindChild(child, childType, childName);
                    if (foundChild != null) break;
                } else if (!string.IsNullOrEmpty(childName)) {
                    var frameworkElement = child as FrameworkElement;
                    if (frameworkElement != null && frameworkElement.Name == childName) {
                        foundChild = child;
                        break;
                    }
                } else {
                    // child element found.
                    foundChild = child;
                    break;
                }
            }
        }
        return foundChild;
    }
}


次に XAML で ComboBox の添付プロパティを設定します。

<ComboBox ComboBoxBehaviors.IsInputMethodEnabled="False"/>


これで ComboBox の IME が無効になります。


関連記事ComboBox の IME を無効にする方法は?
関連記事フィードバック:WPF の ComboBox のIME を無効にできない


WPF FAQ の目次に戻る