mvvm - Input validation on Windows store app -


I have a two-way binding in a window store app using MVVM in which only numeric values ​​should be allowed. What is the proper procedure to use MVVM when a non-numeric key is pressed?

INOTifyPropertyChanged value is being converted as text boxes Focus loses I basically want quick verification of your qualities I could not find a simple example of the

< / Div>

Why not create an affiliate property to include this behavior? Something like this:

  public class TextBoxHelper {public static bool GetRestrictToNumerical (DependencyObject obj) {return (bool) obj.GetValue (RestrictToNumericalProperty); } Public static zero SetRestrictToNumerical (dependency object obj, bool value) {obj.SetValue (restricted ToNumericalProperty, value); } Public static DependencyProperty RestrictToNumericalProperty = DependencyProperty.RegisterAttached ( "RestrictToNumerical", typeof (bool), typeof (TextBoxHelper), New PropertyMetadata (wrong, onRestrictToNumericalChanged)) read-only; Private Statik Arkshittumumerik Chenjed (dependence on space object D, Dispennseeporfti Chenjed Aventarj e) as {var TB = D text box; If return (TB == blank); If ((bool e.NewValue) tb.KeyDown + = tb_KeyDown; Else tb.KeyDown - = tb_KeyDown; } Fixed zero tb_KeyDown (Object Sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e) {e.Handled = e.Key & lt; VirtualKey.Number0 || E. K & gt; VirtualKey.Number9; }}  

You will use this in your XML:

  & lt; Page x: Class = "App4.MainPage" xmlns = "http: //schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns: x = "http://schemas.microsoft.com/winfx/2006/ xaml "xmlns: local = using": App4 "xmlns: d =" Http://schemas.microsoft.com/expression/blend/2008 "xmlns: mc =" http://schemas.openxmlformats.org/markup -compatibility / 2006 "MC: Ignorable =" d "& gt; & Lt; Grid Background = "{ThemeResource ApplicationPageBackgroundThemeBrush}" & gt; & Lt; Text box vertical alignment = "center" local: textbox ornamentation. Rationality = "True" InputScope = "Number" /> & Lt; / Grid & gt; & Lt; / Page & gt; In my opinion, in my opinion, there is a clean MVVM approach for all input considerations that you may have to make. It is probably more likely for your simple question, but this is more sophisticated assumptions. Good for 


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -