Coder Social home page Coder Social logo

Comments (3)

ReedCopsey avatar ReedCopsey commented on September 26, 2024

WPF is very "fussy" about threading issues. Simple properties can be set from other threads, but anything that touches the UI in more convoluted ways (commands, collections, etc) must always be set, or at least notified, from the UI thread.

In this case, it's the Command's CanExecuteChanged event - that needs to happen on the UI thread.

We don't track the current context within every command - it adds quite a bit of overhead. However, the dependency notification system does provide a mechanism to allow this. Unfortunately, it got hidden in the major API update recently.

I've just pushed Version 1.0.6 to NuGet ( https://www.nuget.org/packages/FSharp.ViewModule.Core/1.0.6 ), which re-exposes this.

With this release, you can now make any ViewModel become "thread aware" on an opt-in basis by adding a single line of code. Just change your definition to:

type MyViewModel () as this =
    inherit ViewModelBase ()
    do
        this.DependencyTracker.SynchronizationContext <- System.Threading.SynchronizationContext.Current

    // ... rest of your code here

This causes all dependent property notifications to post to the UI thread, which should solve your issue.

from fsharp.viewmodule.

ReedCopsey avatar ReedCopsey commented on September 26, 2024

Going to close this - feel free to reopen if you're still having issues, or ask if you need more clarification.

from fsharp.viewmodule.

Ummon avatar Ummon commented on September 26, 2024

Thanks for your answer. It solves my problem.

from fsharp.viewmodule.

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.