Hello,
I am trying to have a numeric box in WPF toolbox, I have the following code which is giving me the control in the tool box, but I am unable make it accept only the numeric input.
protected override void OnKeyDown(KeyEventArgs e)
{
short val;
if (!Int16.TryParse(e.key.ToString(), out val))
{
e.Handled = true;
}
}
The problem I am facing is:
1 - When I press the numeric key 1 the value taken is D1 where it is treated as a character and displayed in Textbox
2- The Xaml designer is not coming up
Window x:Class="TEST.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" xmlns:my="clr-namespace:TEST">
<Grid>
<my:NumericTextBox Height="23" HorizontalAlignment="Left" Margin="183,128,0,0" x:Name="TextBox1" VerticalAlignment="Top" Width="75" />
</Grid>
</Window>
The error is
Error 1 Undefined CLR namespace. The 'clr-namespace' URI refers to a namespace 'TEST' that is not included in the assembly.
Error 2 The type 'my:NumericTextBox' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
However I am still able to run the app
I want to have a custom control for textbox accepting only numerics.Please suggest....
Regards