I am going through your articles and demo projects for Cinch v2 for our WPF project and find Cinch v2 a great tool to use. Thanks for your hardworking and amazing work!
I am follwing a simple demo using Cinch v2 and trying out MediatorSinkMessage between/among Views. But I am getting an error when trying to add a new Workspacedata to ViewModelBase.Views collection in MainWindowViewModel via MediatorMessageSink call. This
may be the issue which have already been talked about or resolved, but I can't seem to find any references...
An exception thrown is NotSupportException, "This type of CollectionView does not support changes to its SourceCollection from a thread different from the Dispatcher thread."
The error is probably WPF generic error on ObservableCollection as ObservableCollection doesn't support changes to SourceCollection from a different thread. I like the idea of Cinch Workspace data and of using Collection to keep track of available views in
MainWindowView (just like your demo).
Your demo seems to create views in static way, on ViewAwareStatus ViewLoaded event. Our project oftern involves creating/adding new Views at runtime. Hence, I'd like to have a common method to add a new Workspacedata to Views in MainWindowViewModel and have
it called via MessageSink.
In demo, I have:
- MainWindowView which inherits from Cinch.ViewModelBase and contains TabControlEx bound to Cinch out-of-box 'Views' collection
- HomeView which contains a button 'Create New View' and which is created as the first Workspacedata item on ViewAwareStatusService ViewLoaded event in MainWindowViewModel
- BlahView which simply displays some text (e.g. "blah blah blah blah")
- MainWindowViewModel has some method, say 'OnCreateNewBlahView' with MediatorMessageSinck "CreateNewBlahViewMessage". Within the method, all it does is to create a new Workspacedata (null, "BlahView", null, "New Blah",
true), and add it to Views
- HomeViewModel has a method 'ExecuteCreateNewViewCommand' simply to send a message back to MainWindowViewModel by notifying
When NotifyCollegues is called from HomeViewModel, the line in MediatorSingleton.cs gets the error:
foreach (var cb in wrCopy)
Delegate action = cb.GetMethod();
if (action != null)
DynamicInvoke method invokes the common method 'OnCreateNewBlahView' in MainWindowViewModel, but ObservableCollectio Cinch.Views doesn't like to be modified at this point.
Is there better way to handle runtime creation of Workspacedata via MediatorMessageSink to Views? I'd prefer not to rewrite ObservableCollection 'Views' (and functionality) to something like multi-threading ObservableCollection (e.g. your DispatcherNotifiedObservableCollection),
if I can avoid it.
Any suggestions very much appreciated