Coder Social home page Coder Social logo

Comments (12)

StanleyGoldman avatar StanleyGoldman commented on May 2, 2024 3

Can confirm workaround works: https://github.com/StanleyGoldman/UnderstandReactiveUIProblem/tree/validation-fix

GitHub
Contribute to StanleyGoldman/UnderstandReactiveUIProblem development by creating an account on GitHub.

from reactiveui.validation.

open-collective-bot avatar open-collective-bot commented on May 2, 2024

Hey @Micha-kun 👋,

Thank you for opening an issue. We will get back to you as soon as we can. Also, check out our Open Collective and consider backing us.

https://opencollective.com/reactiveui

PS.: We offer priority support for all backers. Don't forget to add priority label when you start backing us 😄

An advanced, composable, functional reactive model-view-viewmodel framework for all .NET platforms!

from reactiveui.validation.

glennawatson avatar glennawatson commented on May 2, 2024

Hi @Micha-kun are you able to provide a small repository with a sample of your problem?

from reactiveui.validation.

Micha-kun avatar Micha-kun commented on May 2, 2024

Hi @glennawatson I filled about the bug with new info. I'll try to make that repository later and share with you.

Thank you

from reactiveui.validation.

Micha-kun avatar Micha-kun commented on May 2, 2024

Here is the repository sample:

https://github.com/Micha-kun/ReactiveUI.Validation.BugTest

GitHub
Contribute to Micha-kun/ReactiveUI.Validation.BugTest development by creating an account on GitHub.

from reactiveui.validation.

Micha-kun avatar Micha-kun commented on May 2, 2024

I found that if I create the ValidationContext instance with RxApp.TaskpoolScheduler, it works as expected. By default it uses RxApp.MainThreadScheduler and, with this scheduler it doesn't refresh... Maybe in WinForms it requires to use TaskpoolScheduler as default?

from reactiveui.validation.

miqueljuan avatar miqueljuan commented on May 2, 2024

I found the same problem working in WPF, if i use the ValidationContext with RxApp.TaskpoolScheduler on my abstract class it works as expected, else throws ArgumentOutOfRangeException.

Without using an abstract class, with all the properties declared on the validated ViewModel it works with RxApp.MainThreadScheduler.

Special Characteristics:

  • ReactiveUI.Validation version is 1.2.1
  • Project target .NET Framework 4.7.2
  • WPF project is a C# project.
  • ViewModel project is a C# project.

from reactiveui.validation.

StanleyGoldman avatar StanleyGoldman commented on May 2, 2024

I recently hit this issue and I have a repro: https://github.com/StanleyGoldman/UnderstandReactiveUIProblem/tree/validation

GitHub
Contribute to StanleyGoldman/UnderstandReactiveUIProblem development by creating an account on GitHub.

from reactiveui.validation.

kagerouttepaso avatar kagerouttepaso commented on May 2, 2024

If you set the ViewModel after resolving the main thread queue, no exception will occur.

    internal class Program
    {
        [STAThread]
        public static void Main()
        {
            var app = new App();
            var vm = new MainWindowViewModel();
            var window = new MainWindowView();

            Service.DoEvennts();
            window.ViewModel = vm;

            app.Run(window);
        }
    }

    public static class Service
    {
        [SecurityCritical]
        [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
        public static void DoEvennts()
        {
            DispatcherFrame frame = new DispatcherFrame();
            Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background,
                new DispatcherOperationCallback(ExitFrames), frame);
            Dispatcher.PushFrame(frame);
        }

        public static object ExitFrames(object f)
        {
            ((DispatcherFrame)f).Continue = false;
            return null;
        }
    }

from reactiveui.validation.

kagerouttepaso avatar kagerouttepaso commented on May 2, 2024

I want IObservableList to be published as a public property.For simple collection access, you can use IObservableList .Items.
The problem of scheduler is caused by using ReadOnlyObservableCollection .I think that scheduler-aware coding, including creation of ReadOnlyObservableCollection, should be done by library users.
Currently I use the following extension methods for binding to a View.

public static IObservable<IList<ValidationState>> ResolveValidationStatusChanges<TViewModel, TViewModelProperty>(
    this TViewModel vm,
    Expression<Func<TViewModel, TViewModelProperty>> viewModelProperty,
    bool exclusively = true)
       where TViewModel : ReactiveObject, IValidatableViewModel
{
    var field = typeof(ValidationContext).GetField("_validationSource", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance);
    var sourcelist = (SourceList<IValidationComponent>)field.GetValue(vm.ValidationContext);
    IObservableList<IValidationComponent> observableList = sourcelist.AsObservableList();

    return observableList
        .Connect()
        .ToCollection()
        .Select(c => Observable.CombineLatest(c
            .OfType<BasePropertyValidation<TViewModel, TViewModelProperty>>()
            .Where(x => x.ContainsProperty(viewModelProperty, exclusively))
            .Select(x => x.ValidationStatusChange)))
        .Switch();
}
ViewModel.ResolveValidationStatusChanges(x => x.IpAddress)
    .Select(x => string.Join(",", x.Where(b => !b.IsValid).SelectMany(b => b.Text)))
    .ObserveOn(RxApp.MainThreadScheduler)
    .BindTo(this, v => v._test.Text)
    .DisposeWith(d);

from reactiveui.validation.

worldbeater avatar worldbeater commented on May 2, 2024

This should have been fixed in #82. With ReactiveUI.Validation from the main branch, the ArgumentOutOfRangeException is no longer thrown in BindValidation, and the ValidationContext is performing as expected, at least in my WPF playground 🎉 Feel free to reopen if you stumble upon this again.

from reactiveui.validation.

github-actions avatar github-actions commented on May 2, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

from reactiveui.validation.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.