idataerrorinfo

Combining DataAnnotations and IDataErrorInfo for WPF

社会主义新天地 提交于 2019-12-07 05:23:53
问题 I am writing a WPF application and I want to use Data Annotations to specify things like Required Fields, Range , etc. My ViewModel classes use the regular INotifyPropertyChanged interface and I can validate the entire object easily enough using the C# 4 Validator , but I would also like the fields to highlight red if they do not validate properly. I found this blog post here (http://blogs.microsoft.co.il/blogs/tomershamam/archive/2010/10/28/wpf-data-validation-using-net-data-annotations-part

How to force validation errors update on View from ViewModel using IDataErrorInfo?

陌路散爱 提交于 2019-12-06 17:12:38
问题 I have a MVVM-based Window with many controls, and my Model implements IDataErrorInfo . There is also a SaveCommand button, which performs validation by analysing Model.Error property. The view displays the default red border around controls with errors only when I change the value of a particular control, or when I notify about the change of that property using PropertyChanged. How can I force View to display all Validation errors even when I didn't touch the controls? All my validation

Is IDataErrorInfo ignored during model validation in MVC 2?

非 Y 不嫁゛ 提交于 2019-12-06 11:56:10
I currently migrated my project to MVC 2 and IDataErrorInfo doesn't seem to work when using default model binding and validation. Is it cut out? SUMMARY I posted this error to MVC 2 issue tracker: http://aspnet.codeplex.com/WorkItem/View.aspx?WorkItemId=4891 It will be resolved in next preview release. DefaultModelBinder in MVC 1.0: protected virtual void OnPropertyValidated(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor, object value) { IDataErrorInfo model = bindingContext.Model as IDataErrorInfo; if (model != null) { string str

Combining DataAnnotations and IDataErrorInfo for WPF

跟風遠走 提交于 2019-12-05 11:26:18
I am writing a WPF application and I want to use Data Annotations to specify things like Required Fields, Range , etc. My ViewModel classes use the regular INotifyPropertyChanged interface and I can validate the entire object easily enough using the C# 4 Validator , but I would also like the fields to highlight red if they do not validate properly. I found this blog post here (http://blogs.microsoft.co.il/blogs/tomershamam/archive/2010/10/28/wpf-data-validation-using-net-data-annotations-part-ii.aspx) that talks about how to write your base view model to implement IDataErrorInfo and simply use

WPF- Validation -The validation error message goes behind the other controls because of AdornerDecorator

可紊 提交于 2019-12-05 11:09:29
I have implemented IDataErrorInfo in my ViewModel to return a string if the text box has error. public string this[string columnName] { get { return "Error-- This is a long error message - sd"; } } But this error message goes behind the other control on the UI as shown below. Below is the xaml: <Window x:Class="Test.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="600" Width="600"> <Window.Resources> <ControlTemplate x:Key="validationTemplateNew"> <DockPanel LastChildFill="True"> <TextBlock

Tooltip Not Showing Up When No Validation Error WPF

怎甘沉沦 提交于 2019-12-05 10:01:59
I searched and did not see a solution. I can only get the validation to show the tooltip if I do not set a tooltip in the combo box tooltip property. I would like to see the validation error tooltip when one is present otherwise show the tooltip from the combobox property. The validation tooltip shows up fine when I remove the text from the tooltip property (i.e. from the property panel for the combo box). The XAML in Application.Resources (App.XAML)for the tooltip to show the validation error is <Style x:Key="StandardComboBoxStyle" TargetType="{x:Type ComboBox}"> <Style.Triggers> <Trigger

How to force validation errors update on View from ViewModel using IDataErrorInfo?

人走茶凉 提交于 2019-12-05 00:26:02
I have a MVVM-based Window with many controls, and my Model implements IDataErrorInfo . There is also a SaveCommand button, which performs validation by analysing Model.Error property. The view displays the default red border around controls with errors only when I change the value of a particular control, or when I notify about the change of that property using PropertyChanged. How can I force View to display all Validation errors even when I didn't touch the controls? All my validation bindings include ValidatesOnDataErrors=True, NotifyOnValidationError=True . I know one solution is to have

Force IDataErrorInfo validation

痞子三分冷 提交于 2019-12-03 23:25:59
I have two controls on some panel: textbox and combobox: <TextBox Text="{Binding ShapeName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" /> <ComboBox SelectedItem="{Binding ActiveStageViewModel, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" /> I need to force idataerrorinfo validation for textbox, when I select something on combobox. How to do that? The code from viewmodel: string IDataErrorInfo.this[string propertyName] { get { var error = string.Empty; if (propertyName == Expression.GetPropertyName(() =>

Using IDataErrorInfo with Nested Objects

ぃ、小莉子 提交于 2019-12-03 16:25:47
I am using MVVM and I want to use IDataErrorInfo to validate my View. My current implementation includes Nested objects and different ViewModels. e.g. Business Entity 'Customer' contains Business Entity 'Address'. I am accessing Address directly in my view, like "Customer.Address". To validate changes in Address I would have to implement IDataErrorInfo in Address. I use Customer or Address in different Views/ViewModels. Usage in different Views/ViewModels lead to different Validation Behavior. Thus, implementing the validation in the Entity itself is insufficient. Exposing the properties I

IDataErrorInfo vs ValidationRule vs Exception

空扰寡人 提交于 2019-12-03 15:14:40
问题 Can anyone tell me which is a better approach for Validation in WPF. Implementing IDataErrorInfo Creating ValidationRule Throwing Exceptions in terms of performance, memory leaks, code maintainability and re-use. 回答1: This is kind of a complex request, and honestly it'll probably vary based on preference more than anything else. But, here's my understanding: Performance : Exceptions will lose nearly every time unless your other implementations are horrendous. There's significant overhead to