feature: Bind validation to non-string view properties
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
从现有的 BindValidation 和 OneWayBind API 开始,使用提议的泛型签名以及 WhenAnyObservable 替代方案作为行为上下文。确定如何通过 selector 将验证状态映射到非 string 类型的 view 属性;当所请求的重载支持 Color-style binding,同时保留现有的验证行为时,即视为完成。
由索引模型根据 Issue 内容生成。
描述
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
- 主要语言
- C#
- 星标
- 273
- 派生
- 30
- 平均合并
- 52 分钟
- 30 天内合并 PR
- 3
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
reactiveui/ReactiveUI.Validation 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 20/100
reactiveui/ReactiveUI.Validation#634 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 25/100
reactiveui/ReactiveUI.Validation#511 ·
维护者通常 1 天内回复
-
enhancement
难度 4/5 3-5 天 新手友好度 35/100
reactiveui/ReactiveUI.Validation#414 · 2 条评论 ·
维护者通常 1 天内回复
-
Performance
难度 3/5 1-2 天 新手友好度 35/100
reactiveui/ReactiveUI.Validation#117 ·
维护者通常 1 天内回复
查看 reactiveui/ReactiveUI.Validation 的全部 Issue
相似的 Issue
-
Bug: Needs Replicating
难度 2/5 1-3 小时 新手友好度 62/100
space-wizards/RobustToolbox#7189 ·
维护者通常 1 天内回复
-
enhancement needs-triage
难度 2/5 1-3 小时 新手友好度 78/100
microsoft/microsoft-ui-reactor#1460 ·
维护者通常 1 天内回复
-
t/bug
难度 2/5 1-3 小时 新手友好度 75/100
dotnet/maui#39950 · 1 个 reaction ·
维护者通常 1 天内回复
-
The server's default HttpClient fails on plain http and on HTTPS servers without HTTP/2可能已有人在做 @yasmoradi 今天认领。 未关闭area / templates
难度 2/5 1-3 小时 新手友好度 73/100
bitfoundation/bitplatform#14659 ·
维护者通常 1 天内回复
-
DbTransaction.SupportsSavepoints docs say Release/ReleaseAsync are expected to throw, but they are no-ops by design可能已有人在做 @alaricd 今天认领。 未关闭area-System.Transactions untriaged
难度 2/5 1-3 小时 新手友好度 72/100
dotnet/runtime#137040 · 1 条评论 ·
维护者通常 1 天内回复