Reputation: 403
One textbox in a page.
i can not use the converter (it is not worked) and I can not use CharacterCasing property
How can I put in uppercase my Textbox when i write a text ?
I use Windows runtime to develop for Windows 8.1 so I do not find many help on the internet
My code for the moment :
KeyUp :
String str = "hello";
str = str.ToUpper();
str.Select(str.Count(), 0);
KeyDown :
bool bModify = true;
My XAML code :
<TextBox Name="Name" KeyUp="KeyUp" FontSize="20" Margin="15" Grid.Column="1" Grid.Row="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" KeyDown="KeyDown"/>
Upvotes: 0
Views: 804
Reputation: 31724
You could leave the TextBox
as is, but when not in focus - hide it and show a TextBlock
instead with the same text, but with something like Typography.Capitals="SmallCaps"
set.
Otherwise - this might work:
<TextBox
x:Name="tb"
Width="500"
VerticalAlignment="Center"
HorizontalAlignment="Center"
KeyDown="OnKeyDown"
TextChanged="OnTextChanged"/>
C#
private void OnKeyDown(object sender, KeyRoutedEventArgs e)
{
DoTheAllCapsThing();
}
private void OnTextChanged(object sender, TextChangedEventArgs e)
{
DoTheAllCapsThing();
}
private void DoTheAllCapsThing()
{
var start = tb.SelectionStart;
var length = tb.SelectionLength;
tb.Text = tb.Text.ToUpper();
tb.Select(start, length);
}
Upvotes: 5