This is my custom textBox:
public class TextBoxInputNumbers : TextBox
{
Regex regex;
public enum DatatypesInput
{
Integer, Decimals
}
public TextBoxInputNumbers()
{
DatatypeInput = DatatypesInput.Integer;
}
public DatatypesInput DatatypeInput
{
set
{
switch (value)
{
case DatatypesInput.Integer:
regex = new Regex("[^0-9.-]+");
break;
case DatatypesInput.Decimals:
regex = new Regex("[^0-9-]+");
break;
}
}
}
protected override void OnPreviewTextInput(System.Windows.Input.TextCompositionEventArgs e)
{
e.Handled = regex.IsMatch(e.Text);
}
}
And I’d like to show the property DatatypeInput in XAML, but they cannot recognize any element of my enum.
You can convert the enun name to a string using the Enum.GetName() method:
and then bind to that value in your XAML.
Is that what you are looking for? Use Enum.GetNames() is you need the list of all valid names.