我正在尝试绑定类型上文本框的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不会改变。
答案 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;
}