我正在尝试将文本框的 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 没有改变。