2

我正在尝试将文本框的 InputScope 值绑定到类型上。为此,我使用转换器:

xml:

<TextBox 
    Style="{StaticResource TextBoxStyle}"
    InputScope="{Binding Type, Converter={StaticResource typetoInputScope}, Mode=TwoWay}">

转换器:

public class TypeToInputScope : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, string language)
    {
        Type type = (Type)value;
        if (type == typeof(string))
        {
            return InputScopeNameValue.AlphanumericHalfWidth;
        }
        else
        {
            return InputScopeNameValue.Number;
        }
    }

    public object ConvertBack(object value, Type targetType, object parameter, string language)
    {
        throw new NotImplementedException();
    }
}

当我在 VS 中调试时,它进入转换器,但 InputScope 没有改变。

4

1 回答 1

1

好的,这里是:

        public object Convert(object value, Type targetType, object parameter, string language)
    {
        Type type = (Type)value;
        InputScope scope = new InputScope();
        InputScopeName name = new InputScopeName();

        if (type == typeof(string))
        {
            name.NameValue = InputScopeNameValue.AlphanumericFullWidth;
        }
        else
        {
            name.NameValue = InputScopeNameValue.Number;
        }
        scope.Names.Add(name);
        return scope;
    }
于 2014-08-17T11:05:00.140 回答