Search code examples
wpfconverterswindows-8.1windows-phone-8.1inputscope

Binding InputScope with a converter in Windows Phone 8.1


I'm trying to bind the InputScope Value of a textbox on a type. For this I use a converter :

Xaml :

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

Converter :

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();
    }
}

When i debug in VS, it goes in the converter, but the InputScope doesn't change.


Solution

  • Ok, here it is :

            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;
        }