小编K. *_*cov的帖子

是否可以在 WPF 中使用 ReactiveUI 绑定来仅使用 INotifyDataErrorInfo 验证用户输入?

我们在 .Net Core WPF 应用程序中使用 ReactiveUI.WPF 11.0.1。我们正在考虑用基于 ReactiveUI 的绑定替换所有基于 XAML 的绑定。有一个用于实现 INotifyPropertyChanged 和 INotifyDataErrorInfo 的域类型的 ViewModel:

public class ItemViewModel : INotifyPropertyChanged, INotifyDataErrorInfo
{
    private string Error => string.IsNullOrEmpty(Name) ? "Empty name" : string.Empty;
    private string _name;

    public string Name
    {
        get => _name;
        set
        {
            _name = value;
            OnPropertyChanged();
        }
    }

    public IEnumerable GetErrors(string propertyName)
    {
        if (string.IsNullOrEmpty(Error))
            return Enumerable.Empty<string>();
        return new[] {Error};
    }

    public bool HasErrors => !string.IsNullOrEmpty(Error);
    public event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged;

    public event PropertyChangedEventHandler PropertyChanged;

    private void OnPropertyChanged([CallerMemberName] …
Run Code Online (Sandbox Code Playgroud)

validation wpf fluentvalidation reactiveui

5
推荐指数
1
解决办法
707
查看次数

如何使用 ReactiveUI 和 DynamicData 将可变模型的 ObservableCollection&lt;T&gt; 绑定到视图模型的 ReadOnlyObservableCollection&lt;T&gt;

我在我的 C# 项目中使用 ReactiveUI 和 DynamicData。但是,域模型类仍然依赖于 C# 事件、INotifyPropertyChanged 和 INotifyCollectionChanged 接口。

有 Model 和 ViewModel 类:

public class Model
{
    public ObservableCollection<int> Collection { get; } = new ObservableCollection<int>();
}

public class ViewModel : ReactiveObject, IDisposable
{
    private readonly CompositeDisposable _cleanUp;
    private readonly SourceList<int> _collectionForCurrentBModel = new SourceList<int>();
    private Model _model = new Model();
    private IDisposable _tempCleanUp = Disposable.Empty;

    public ViewModel()
    {
        _cleanUp = new CompositeDisposable();
        _collectionForCurrentBModel.Connect()
            .Bind(out var aModelsForCurrentBModel)
            .Subscribe(Console.WriteLine)
            .DisposeWith(_cleanUp);
        CollectionForCurrentBModel = aModelsForCurrentBModel;

        this.WhenAnyValue(x => x.Model.Collection) // Every …
Run Code Online (Sandbox Code Playgroud)

inotifycollectionchanged inotifypropertychanged system.reactive reactiveui

2
推荐指数
1
解决办法
989
查看次数