wpf

Prosta walidacja textbox

Walidacja tylko liczby

private void NumericOnly(System.Object sender, System.Windows.Input.TextCompositionEventArgs e)
{
            e.Handled = IsTextNumeric(e.Text);
}
 
 
private static bool IsTextNumeric(string str)
{
            System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex("[^0-9]");
            return reg.IsMatch(str);
}

XAMP

<TextBox PreviewTextInput="NumericOnly" />

Poniżej link do obszernego użycia walidacji
http://www.codeproject.com/Articles/15239/Validation-in-Windows-Presentation-Foundation

Kategoria: 

Format waluty na postawie systemu

1) In app.xaml override OnStartup() and add

 System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("et-EE");

2) Define in XAML @ Window level -

xmlns:sysglb="clr-namespace:System.Globalization;assembly=mscorlib"

3) In XAML

<TextBox Text="{Binding Path=Price, StringFormat='{}{0:C}', ConverterCulture={x:Static sysglb:CultureInfo.CurrentUICulture}}" />

This correctly picks up any custom regional settings. Although I'm using a manually created CultureInfoin the first step, I'm sure it's possible to pass in one of the static types - eg.System.Globalization.CultureInfo.CurrentCulture (I haven't tested it though...)

Kategoria: 

Strony

Subskrybuj wpf