feature: Bind validation to non-string view properties
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
Research direction
Start from the existing BindValidation and OneWayBind APIs, using the proposed generic signatures and the WhenAnyObservable alternative as behavioral context. Determine how validation state is mapped to a non-string view property through the selector; done means the requested overload supports the Color-style binding while preserving existing validation behavior.
Written by the indexing model from the issue text.
Description
Is your feature request related to a problem? Please describe.
Not related to a problem.
Describe the solution you'd like
So what I'm trying to do is change the color of control in my view based on the validation state of a validation helper. The control does have an error property or something similar, and I do not want to show an inline error message anyway for this particular situation. What I would like to be able to do is something like this:
this.BindValidation(ViewModel, viewModel => viewModel.Property, view => view.Control.Color,
validationState => validationState.IsValid ? Color.Green : Color.Red);
This would similar to the overload of the OneWayBind function that allows you to bind between types like so:
this.OneWayBind(ViewModel, viewModel => vm.BoolProperty, view => view.Control.Color,
boolProperty => boolProperty ? Color.Green : Color.Red);
Describe alternatives you've considered
Currently this is how I'm achieving the same effect:
this.WhenAnyObservable(v => v.ViewModel.PropertyValidator.ValidationChanged)
.Select(validationState => validationState.IsValid ? Color.Green : Color.Red)
.BindTo(this, v => v.Control.Color);
This works, and I don't necessarily hate it, but I would prefer the proposed form for brevity and to match with the rest of my simple bindings.
Describe suggestions on how to achieve the feature
I'm not sure exactly how to make this work or I probably just would have made done it and made PR, but I think the signatures of the overloads for such a change would look something like this:
public static IDisposable BindValidation<TView, TViewModel, TViewModelProperty, TViewProperty>(
this TView view,
TViewModel? viewModel,
Expression<Func<TViewModel, TViewModelProperty>> viewModelProperty,
Expression<Func<TView, TViewProperty>> viewProperty,
Expression<Func<IValidationState, TViewProperty>> selector,
IValidationTextFormatter<string>? formatter = null)
where TView : IViewFor<TViewModel>
where TViewModel : class, IReactiveObject, IValidatableViewModel
and this:
public static IDisposable BindValidation<TView, TViewModel, TViewProperty>(
this TView view,
TViewModel? viewModel,
Expression<Func<TViewModel?, ValidationHelper?>> viewModelHelperProperty,
Expression<Func<TView, TViewProperty>> viewProperty,
Expression<Func<IValidationState, TViewProperty>> selector,
IValidationTextFormatter<string>? formatter = null)
where TView : IViewFor<TViewModel>
where TViewModel : class, IReactiveObject, IValidatableViewModel
Additional context
- Dominant language
- C#
- Stars
- 273
- Forks
- 30
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from reactiveui/ReactiveUI.Validation
-
Dependency DashboardOpen
Difficulty 3/5 1-2 days Newbie friendliness 20/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 35/100
reactiveui/ReactiveUI.Validation#414 · 2 comments ·
-
Performance
Difficulty 3/5 1-2 days Newbie friendliness 35/100
All issues in reactiveui/ReactiveUI.Validation
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Facepunch/sbox-public#12456 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
mcneel/rhino.inside-revit#1736 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
reactiveui/Primitives#254 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Kyrodan/KeeAnywhere#510 ·
-
area-Tools-ILLink untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day