pglazkov / mvvmvalidation Goto Github PK
View Code? Open in Web Editor NEWLightweight library that helps reduce boilerplate when implementing validation in XAML MVVM applications
License: MIT License
Lightweight library that helps reduce boilerplate when implementing validation in XAML MVVM applications
License: MIT License
When trying to build the sample project (MvxSamples.Validation) or my own Solution with MvvMValidation included I get the error The target "_FindCompiledJavaFiles" does not exist in the project.
It happens on the Xamarin.Android.Common.targets file on:
DependsOnTargets="$(_CompileToDalvikDependsOnTargets)"
Which refers to:
<_CompileToDalvikDependsOnTargets> _FindCompiledJavaFiles; _GetMonoPlatformJarPath; _GetAdditionalResourcesFromAssemblies; _CreateAdditionalResourceCache; _GetLibraryImports </_CompileToDalvikDependsOnTargets>
I am building on .Net Standard 2.0. My JAVA and SDK location should be ok:
Java: C:\Program Files\Java\jdk1.8.0_144
Android SDK: C:\Program Files (x86)\Android\android-sdk
Additional info:
sorry for posting about this again. i didn't find any clear resolution.
in visual studio 2017 (mac), i was able to get an application to compile and run. this project uses mvvmcross and mvvmvalidation. in 2017, i was able to switch the mono runtimes but i cannot do that now in visual studio 2019(mac). i try to compile the application and i have these such errors:
CS0246: The type or namespace name 'MvvmValidation' could not be found (are you missing a using directive or an assembly reference?) (CS0246) (QAQC)
i have seen people say, change the target of your platform to .net standard or whatever. doing that, it's going to break other packages or references. right now the pcl project is using profile 78.
which versions of mvvmvalidation are compatible with profile 78. or has anyone else have been having this issue?
Compilation in Visual Studio for Mac fails with the message: The type or namespace name 'MvvmValidation' could not be found (are you missing a using directive or an assembly reference?)
After opening the same project and build in Xamarin Studio it works perfectly.
ResultChanged event is called on a wrong thread (non-UI) when synchronous validation is executed (ValidationHelper.Validate(...)).
===== Main exception =====
MvvmValidation.ValidationException: An exception occurred during validation. See inner exception for details. ---> System.InvalidOperationException: The calling thread cannot access this object because a different thread owns it.
at System.Windows.Threading.Dispatcher.VerifyAccess()
at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
at XXX.Views.Main.ProjectDataV.set_ComputeVolumePreReqOK(Boolean value) in c:\Users\xga\Dev\geonX\Virfac-AM\Virfac-iAM\Views\Main\ProjectDataV.xaml.cs:line 44
at XXX.Views.Main.ProjectDataV.UpdatePreReqs(Object sender, PropertyChangedEventArgs e) in c:\Users\xga\Dev\geonX\Virfac-AM\Virfac-iAM\Views\Main\ProjectDataV.xaml.cs:line 125
at System.Windows.WeakEventManager.ListenerList`1.DeliverEvent(Object sender, EventArgs e, Type managerType)
at System.ComponentModel.PropertyChangedEventManager.OnPropertyChanged(Object sender, PropertyChangedEventArgs args)
at GalaSoft.MvvmLight.ObservableObject.RaisePropertyChanged(String propertyName)
at YYYLib.Mvvm.ViewModels.MvvmVM.set_IsValid(Boolean value) in c:\Users\xga\Dev\geonX\Virfac-AM\YYYLib.Mvvm\ViewModels\MvvmVM.cs:line 152
at YYYLib.Mvvm.ViewModels.MvvmVM.CheckAndUpdateValidity() in c:\Users\xga\Dev\geonX\Virfac-AM\YYYLib.Mvvm\ViewModels\MvvmVM.cs:line 317
at YYYLib.Mvvm.ViewModels.MvvmVM.OnValidationResultChanged(Object sender, ValidationResultChangedEventArgs e) in c:\Users\xga\Dev\geonX\Virfac-AM\YYYLib.Mvvm\ViewModels\MvvmVM.cs:line 297
at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
at MvvmValidation.ValidationHelper.NotifyResultChanged(Object target, ValidationResult newResult, SynchronizationContext syncContext, Boolean useSyncContext) in E:\Pasha\Dev\MyProjects\MvvmValidation\MvvmValidation.Portable\ValidationHelper.cs:line 999
at MvvmValidation.ValidationHelper.SaveRuleValidationResultAndNotifyIfNeeded(ValidationRule rule, RuleResult ruleResult, SynchronizationContext syncContext) in E:\Pasha\Dev\MyProjects\MvvmValidation\MvvmValidation.Portable\ValidationHelper.cs:line 840
at MvvmValidation.ValidationHelper.<>c__DisplayClass46_0.<ExecuteNextRuleFromQueueAsync>b__0(Task`1 t) in E:\Pasha\Dev\MyProjects\MvvmValidation\MvvmValidation.Portable\ValidationHelper.cs:line 759
at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- End of inner exception stack trace ---
at MvvmValidation.ValidationHelper.ValidateInternal(Object target) in E:\Pasha\Dev\MyProjects\MvvmValidation\MvvmValidation.Portable\ValidationHelper.cs:line 686
at MvvmValidation.ValidationHelper.Validate(String targetName) in E:\Pasha\Dev\MyProjects\MvvmValidation\MvvmValidation.Portable\ValidationHelper.cs:line 607
at YYYLib.WorkItems.ViewModels.WorkItemsManagerVM.set_IsEmptyItemBounds(Boolean value) in c:\Users\xga\Dev\geonX\Virfac-AM\YYYLib.WorkItems\ViewModels\WorkItemsManagerVM.cs:line 68
===== Inner exception =====
System.InvalidOperationException: The calling thread cannot access this object because a different thread owns it.
at System.Windows.Threading.Dispatcher.VerifyAccess()
at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
at XXX.Views.Main.ProjectDataV.set_ComputeVolumePreReqOK(Boolean value) in c:\Users\xga\Dev\geonX\Virfac-AM\Virfac-iAM\Views\Main\ProjectDataV.xaml.cs:line 44
at XXX.Views.Main.ProjectDataV.UpdatePreReqs(Object sender, PropertyChangedEventArgs e) in c:\Users\xga\Dev\geonX\Virfac-AM\Virfac-iAM\Views\Main\ProjectDataV.xaml.cs:line 125
at System.Windows.WeakEventManager.ListenerList`1.DeliverEvent(Object sender, EventArgs e, Type managerType)
at System.ComponentModel.PropertyChangedEventManager.OnPropertyChanged(Object sender, PropertyChangedEventArgs args)
at GalaSoft.MvvmLight.ObservableObject.RaisePropertyChanged(String propertyName)
at YYYLib.Mvvm.ViewModels.MvvmVM.set_IsValid(Boolean value) in c:\Users\xga\Dev\geonX\Virfac-AM\YYYLib.Mvvm\ViewModels\MvvmVM.cs:line 152
at YYYLib.Mvvm.ViewModels.MvvmVM.CheckAndUpdateValidity() in c:\Users\xga\Dev\geonX\Virfac-AM\YYYLib.Mvvm\ViewModels\MvvmVM.cs:line 317
at YYYLib.Mvvm.ViewModels.MvvmVM.OnValidationResultChanged(Object sender, ValidationResultChangedEventArgs e) in c:\Users\xga\Dev\geonX\Virfac-AM\YYYLib.Mvvm\ViewModels\MvvmVM.cs:line 297
at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
at MvvmValidation.ValidationHelper.NotifyResultChanged(Object target, ValidationResult newResult, SynchronizationContext syncContext, Boolean useSyncContext) in E:\Pasha\Dev\MyProjects\MvvmValidation\MvvmValidation.Portable\ValidationHelper.cs:line 999
at MvvmValidation.ValidationHelper.SaveRuleValidationResultAndNotifyIfNeeded(ValidationRule rule, RuleResult ruleResult, SynchronizationContext syncContext) in E:\Pasha\Dev\MyProjects\MvvmValidation\MvvmValidation.Portable\ValidationHelper.cs:line 840
at MvvmValidation.ValidationHelper.<>c__DisplayClass46_0.<ExecuteNextRuleFromQueueAsync>b__0(Task`1 t) in E:\Pasha\Dev\MyProjects\MvvmValidation\MvvmValidation.Portable\ValidationHelper.cs:line 759
at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
Hello, I have a ListView
that binding to a ObservableCollection<string>
, it display each string
by a TextBox
via its ItemTemplate
, how can I validation each TextBox
?
Hi
I am new in Android development. I have create xamarin android application in visual studio. i am using MVVMValidation v3.1 with MVVMCROSS v6.1 .Validation works in debug mode but not working in Release APK file.
Issues is TextEdit filed in layout is not showing error message .However it doesn't let me go without filling TextEdit field that is correct.
Do i need to register or setup MVVMValidation in code.
Please guide me in this scenario what i have to do.
I used a shadowwindow style in my project,but the errorteplate doesn't dispaly.
I'm looking to use this library to perform multiple validation checks, and returning/displaying any failures.
I notice you explicitly only return the first invalid rule (see below), and I understand that this is likely the most sensible response in most cases. However, would you consider providing an option on the constructor or as a property to bypass this and return all results?
// Skip rule if the target is already invalid
if (failedTargets.Contains(rule.Target))
{
// Assume that the rule is valid at this point because we are not interested in this error until
// previous rule is fixed.
SaveRuleValidationResultAndNotifyIfNeeded(rule, RuleResult.Valid(), syncContext);
return TaskEx.FromResult(true);
}
In version 3.0.0 the error Type 'DataErrorInfoAdapter' is not defined shows up but not in v2.0.2?
I found this interesting library and the readme file only explains how to use it in code, but it doesn't tell how to link the library to a project (via nuget package? via adding source code? etc.)
See this comment.
public class ComplexModel {
public int Number { get; set; }
public string Name { get; set; }
public bool IsOK { get; set; }
}
public class ViewModel : ValidatableViewModelBase {
public ComplexModel Model { get; set; }
public ViewModel() {
Validator.AddRule(...) // how to validate Model.Number == 1 && Model.Name == "xxx" && Model.IsOK ?
}
}
I'm interested in using this library as an implementation for INotifyDataErrorInfo interface. And I want to run validation each time I set a propoerty. Problem is that the Validate() method in this library expects an expression as an input, while I need an overload of it that accepts a string instead. This prevents me from using it inside my generic setter:
protected virtual void SetValue<T>(ref T field, T val, [CallerMemberName] string propertyName = null, Action onValueChanged = null)
{
if (EqualityComparer<T>.Default.Equals(field, val))
return;
field = val;
RaisePropertyChanged(propertyName);
//Need to add validator.Validate(propertyName) here but can't because my param is a string
onValueChanged?.Invoke();
}
Do you have any workaround for this or another approach of executing validation during set? Thanks.
I noticed when looking through the MvvmValidation assembly that AsyncRuleValdateActionExceptions
is misspelled.
I'm referencing the MvvmValidation
package from nuget.org in my .NET 4.6.1 WPF application.
The README
has an example of an adapter that implements NotifyDataErrorInfoAdapter
, but the actual adapter class is nowhere to be found.
It looks like the NuGet Package Manager is adding a reference to the assembly in the net40-client
folder instead of the portable-win8+net45+sl5+wp8
folder.
Unfortunately, when I remove the reference to the net40-client
version and add a reference to the portable-win8+net45+sl5+wp8
version, I am forced to also include a System.Windows
reference, which causes this issue.
Consider adding a ValidationHelper.Validate([CallerMemberName] string propertyName)
overload to help avoid the need for a delegate.
This, within a Name property's getter:
_validationHelper.Validate(() => Name);
_validationHelper.ValidateAsync(() => Name);
becomes this:
_validationHelper.Validate();
_validationHelper.ValidateAsync();
Hi,
at first, thanks for this great library!
But if your UserRegistrationService (In your example) takes, like 1, 2 or more seconds to run, the form is in an false valid or invalid state. The User may edit the username while validating or just press the "submit" button.
Maybe there should be a state object, that you will get by adding a async rule. You could bind to that and disable the text box or do whatever you want. Or the validation state could be set to invalid before execute an async rule.
Regards
abgenullt
Thank you for your open-source library, which has helped me solve many issues in my project. I use FluentValidation extensively in my work, especially its rules that may be used in multiple places. Can we utilize FluentValidation's rules with this library?
NotifyDataErrorInfoAdapter produces a memory leak I think because of
Validator.ResultChanged += (o, e) => OnValidatorResultChanged(o, e, errorsChangedNotificationContext);
this generate event handler leak because at no time is it done
Validator.ResultChanged -=(o, e) => OnValidatorResultChanged(o, e, errorsChangedNotificationContext);
I added the nuget package 2.0.2 and could not find the NotifyDataErrorInfoAdapter
that I had seen in the documentation. Looked in the source and there it was. Looked at the assembly reference and noticed that it was to the path MvvmValidation.2.0.2\lib\net40-client
instead of MvvmValidation.2.0.2\lib\portable-win8+net45+sl5+wp8
I'm trying to follow you sample applying in it to a Xamarin.Forms app but, in the Xaml code I havent been able to find this property: ValidatesOnDataErrors=True
it just doesnt exist on xamarin, so how do you make the validation warnings appear in a Xamarin.Forms app?? where do i retreive them?
Hi there,
How can I remove a specific rule. there is the Validator.RemoveRule function but do not know how to use it?
Copied from CodePlex: http://mvvmvalidation.codeplex.com/workitem/9
I have a problem with validation in WPF 4.5.1 application. I’m executing ValidateAll on object graph with validation rules on main object with some child collection to validate (in sum 150 validation to calculate on all objects). On random occasions (especially first one) validation takes long time (up to 40 seconds) – I have add measured each rule with Stopwatch and each rule is executing shorter than 1ms (it is only in memory if/linq check) and in sum it takes no more than 100ms (when calculating sum of execution of each rule). When I instrumented app I saw that most of time it waits in
var isCompleted = completedEvent.WaitOne(AsyncRuleExecutionTimeout);
and sometimes even throws timeout exception.
Additionally when I’m compering start time of each rule (I have loged timings in database) I can see that there is some bunch of rules executing in small time window and after that is a couple of seconds window and another bunch of rules executing. It looks like there is some problem with locking/waiting. Is this a known problem? Besides this when executing validation next time it can take 100ms or 40s.
First off, great little tool, certainly does the job well!
I'd like to trigger validation of a textbox after it loses focus, but only the validation of that textbox, not then entire view model at once.
To use the example project in the solution posted here, instead of validating all fields when a user clicks on "validate" I'd like to be able to validate the "username" field only when it loses focus, then the "email" field only, when it loses focus, and so on.
Any suggestions on how I could accomplish this with 'MvvmValidation'?
For example, NewPassword, ConfirmPassword.
If the NewPassword is changed or ConfirmPassword, check for similarity.
ValidationHelper.AddRule(
NewPassword,
ConfirmPassword,
RuleResult.Assert(string.Equals( NewPassword, ConfirmPassword), "not equals"));
Not work
Whenever my validated View is deactivated then reactivated (closing then reopening a popup, switching between tabs, etc) I lose all pre-existing error templates on my validating controls.
The validation still persists in the ViewModel.
I've tried:
To no avail.
The only thing that returns the ErrorTemplate is taking the property value out of the error condition then re-entering it to the condition.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.