A lot of examples (even from MS) use a dispatcher to update data-bound properties and a bunch of different answers could be found. Does an 'official' statement exist? Currently, I always use a dispatcher and I would only change this if I can be sure that this is an official feature and it will still work on future .Net versions.
Is a dispatcher needed to change data-bound properties in WPF .Net Core 3 or newer?
287 views Asked by Tom1000 AtThere are 2 answers
Peter Duniho
On
Is a dispatcher needed to change data-bound properties in WPF .Net Core 3 or newer?
No. It's not needed in earlier versions either, nor on .NET Framework versions.
WPF has always automatically marshalled property-change updates to the UI thread as needed, for any properties bound to a dependency property via the normal data binding mechanisms (e.g. {Binding} markup in XAML).
I don't know that this is documented explicitly. I looked around on the Microsoft Docs site, on the most likely topics, such as the data-binding and INotifyPropertyChanged pages for WPF, but didn't see anything. However, it's a well-known feature of WPF, and is mentioned in this 2014 article from MSDN: MVVM : Multithreading and Dispatching in MVVM Applications:
…WPF automatically dispatches the PropertyChanged event to the main thread…
See also e.g. Task parallel library INotifyPropertyChanged NOT throwing an exception?
Note that this is only for simple single-value properties. Collections are a different matter, though WPF since 4.5 has also included some support for automatic marshaling of collection-changed events. See e.g. How do I update an ObservableCollection via a worker thread?
Related Questions in .NET
- file download method in visual studio 2017
- Repository manager receives the wrong connection string in .net core
- MongoDb not connecting C#
- The current .NET SDK does not support targeting .NET Core 6.0. Brand new WPF Project VS Community 2022 17.9.5
- Why Scanning GSI on DynamoDb doesnt work as fast as expected when using CONTAINS?
- Are "blittable types" really unmanaged types for StructLayout Sequential
- Failed to fetch dynamically imported module on Blazor JS Interop
- Problem to upload several images per one request
- Implementing Azure AD B2C Authentication in .NET 8 Blazor Project (RenderMode: InteractiveAuto)
- Stripe connect payout - throws exceptions
- 'IOException: The cloud file provider is not running', when trying to delete 'cloud' folder
- Azure Application Insights Not Displaying Custom Logs for Azure Functions with .NET 8
- Convert C# DateTime.Ticks to Bigquery DateTime Format
- Socket.io nodejs server .NET connection
- Producer Batching Service Bus Vs Kafka
Related Questions in WPF
- Sorting a List by its property renames all the objects in the List
- Can't open new instance of another window in my app, in WPF .NET 8
- Binding forecolour and ToolTip to a DataGrid
- how to create Infinite Upgrades in a clicker game
- Try Catch exception is not catching the unhandled exception
- Assigning an object to another doesn't raise PropertyChanged event in WPF
- Masking input in TextBox
- What should I do if Visual Studio has a restriction on creating files with a long name or a long path to these files?
- reading configuration file (mytest.exe.config)
- WPF Windows Initializing is locking the separated thread in .Net 8
- How to bind to the DataContext ViewModel of another view?
- mouse coordinates in image go below 0 and above width
- WPF pop up is behaving differently in English language PC and Japanese language PC
- Multi level project reference using dll
- Unable to unzip archive .NET framework
Related Questions in MULTITHREADING
- How can I outsource worker processes within a for loop?
- OpenMP & oneTbb difference
- Receiving Notifications for Individual Task Completion OmniThreadLibrary Parallel.ForEach
- C++ error: no matching member function for call to 'enqueue' futures.emplace_back(TP.enqueue(sum_plus_one, x, &M));
- How can I create a thread in Haskell that will restart if it gets killed due to any reason?
- Qt: running callback in the main thread from the worker thread
- Using `static` on a AVX2 counter function increases performance ~10x in MT environment without any change in Compiler optimizations
- Heap sort with multithreading
- windows multithreading CreateMutex
- The problem of "fine-grained locks and two-phase locking algorithm"
- OpenMP multi-threading not working if OpenMPI set to use one or two MPI processor
- WPF Windows Initializing is locking the separated thread in .Net 8
- TCP Client Losing Connection When Writing Data
- vc++ thread constructor throwing compiler error c2672
- ASP.NET Core 6 Web API : best way to pause before resending email
Related Questions in DISPATCHER
- How to write unit test for Application.Current.Dispatcher.BeginInvoke
- Simple event dispatcher in Rust
- Cannot access BitmapImage from async Task
- Wpf ProgressBar not updating During Threading Operation
- MAUI Equivalent for Dispatcher.Run
- MVVMCross how to do heavily work on another thread, do not freeze the UI?
- WPF not disposing viewmodel
- Future and DispatchQueue generating build error
- DispatcherQueue bottleneck in WinUI3
- How to dynamically set Apache ServerName with a system's hostname variable?
- The application called an interface that was marshalled for a different thread error while accessing stream data from miracast receiver?
- How to setup multiple domains on AEM as a cloud service on dispatcher
- How to pass Dispatcher to a class through constructor by Ninject
- DispatcherServlet in Springboot is not working
- Set window owner as window from another Dispatcher thread
Related Questions in DATABOUND-CONTROLS
- Is a dispatcher needed to change data-bound properties in WPF .Net Core 3 or newer?
- Access model bound item inside nested UpdatePanel
- Gridview dataBound add hyperlink to column data from code behind
- Accessing ComboBox.Items with Contains method for DataBound ComboBox
- DataGridView cannot add rows as "control is data-bound" after XML load
- Error in code dealing with Nested Repeaters and Databound label from a SQL database query
- unbound controls table using ADO.NET
- hide the repeated string in repeater
- I need to know how to avoid the System.Data.DataRowview in vb 2010
- How to use bind to apply some change to the database
- Nested Repeater - ItemCommand only fires if attached via markup
- Why DataItem in my custom template databound control is null in ItemCommand event?
- bound text boxes do not show adding new row
- Is there DataBound in DataGrid?
- Which page is my record going to be on?
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
I don't believe an official statement exists. However, it generally seems to depend on the type of update that you're doing. If you're updating a normal property on a VM, then it doesn't matter, if you're updating a dependency property then it does. If you're adding or removing from a list then it doesn't matter, if you're adding or removing from an observable collection then it does.
Generally, I'd say avoid dependency properties in VM's and use INotifyPropertyChanged, leave them to your UserControls. Then you don't have to worry about them. Add a method like DoPropertyChanged(propertyname) to your base class for your VM's so that you can then create a property snippet like VB.net
C#
and quickly add properties to your VM's.
We also make heavy use of index properties and have a snippet for that too. VB
C#