我试图在类型上绑定文本框的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不会改变。
发布于 2014-08-17 11:05:00
好的,这里是:
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;
}https://stackoverflow.com/questions/25348441
复制相似问题