将InputScope与Windows Phone 8.1中的转换器绑定

时间:2014-08-17 10:38:51

标签: wpf converter windows-8.1 windows-phone-8.1 inputscope

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

Xaml:

<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不会改变。

1 个答案:

答案 0 :(得分: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;
    }