【发布时间】:2010-05-10 17:57:29
【问题描述】:
旧版应用转换问题。 VB6 TextBox_KeyDown() 允许更改键(例如,强制击键为大写,但还有许多其他用途)。在 WPF 中如何做到这一点?
我能看到的唯一方法就是处理所有 TextBox 击键。实际上,重新实现 TextBox 编辑。我宁愿不去那里。
【问题讨论】:
标签: wpf key keydown keystrokes
旧版应用转换问题。 VB6 TextBox_KeyDown() 允许更改键(例如,强制击键为大写,但还有许多其他用途)。在 WPF 中如何做到这一点?
我能看到的唯一方法就是处理所有 TextBox 击键。实际上,重新实现 TextBox 编辑。我宁愿不去那里。
【问题讨论】:
标签: wpf key keydown keystrokes
非常快速和肮脏的解决方案。假设您想将 TextBox.Text 值绑定到某个东西,您可以编写一个转换器,它只需在字符串上调用 ToUpper()。
在下面的示例中,文本框绑定到自身。这很可能不是您在生产中想要的,但它可能会激发灵感。
<local:UpperConverter x:Key="toUpperConverter" />
...
<TextBox Text="{Binding RelativeSource={RelativeSource Mode=Self},
Path=Text, Mode=OneWay, Converter={StaticResource toUpperConverter},
UpdateSourceTrigger=PropertyChanged}" />
...
class UpperConverter:IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value.ToString().ToUpper();
}
【讨论】: