In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about basic data validation in Silverlight. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.
Silverlight 2 supports basic data validation features. In Silverlight 2, when we bind data to a UI control, validation rules for that data are automatically bound to that UI control.
For example, if a data field is set to integer, an error occurs when we update the field with non-integer data. We can use this rule to validate input data in the UI. To do this, we simply set two XAML properties and implement the desired UI behavior in the events we define.
For example, the following XAML code defines a set of controls, and the user updates the data through TextBox:
﹤StackPanel x:Name="dataForm"﹥ ﹤TextBlock Text="FirstName" Width="125" FontSize="12" /﹥ ﹤TextBox x:Name="FirstNameTextBox" IsReadOnly="False" Width="150" Text="{Binding FirstName, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}"BindingValidationError="FirstNameTextBox_BindingValidationError"/﹥ ﹤/StackPanel﹥
When both the NotifyOnValidationError and ValidatesOnExceptions properties are set to true, Silverlight triggers the BindingValidationError event when an error occurs validating the bound rule on the input data, so we are notified when validation errors occur.
The next thing we need to do is implement the behavior when the event is triggered, which is the UI behavior we expect. For example:
private void FirstNameTextBox_BindingValidationError(object sender, ValidationErrorEventArgs e){ if (e.Action == ValidationErrorEventAction.Added) { ((Control)e.OriginalSource).Background = new SolidColorBrush(Colors.Red); this.Dispatcher.BeginInvoke(()=>HtmlPage.Window.Alert("The input format is invalid")); } if (e.Action == ValidationErrorEventAction.Removed) { ((Control)e.OriginalSource).Background = new SolidColorBrush(Colors.White); }}
In the above code, when an error occurs, the background color of the control (TextBox in this case) turns red and alerts the user with the warning window of the HTML page. When the error is corrected, the space reverts to its default white color.
Thank you for reading! About "How to carry out basic data validation in Silverlight" This article is shared here, I hope the above content can be of some help to everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see it!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.