n same UserControls with same VM

Jun 23, 2010 at 3:36 PM

Hello,

is it possible to generate more as one UserControl with the same VM but different instances over the meffed viewmodellocator? When i add more as one same UserControl, all UserControls are using the same instance of the ViewModel.

best regards

Helmut

Jun 24, 2010 at 11:21 AM

I think you should specify NonShared as the Creation Policy of the ViewModel:

[PartCreationPolicy(CreationPolicy.NonShared)]

Coordinator
Jul 8, 2010 at 3:56 PM

Helmut,

This should not be happening, I will look into this

Coordinator
Jul 8, 2010 at 8:38 PM
Edited Jul 8, 2010 at 8:38 PM
HelmutE I have looked into this and tried some stuff out, and as bcronje says, all you need to do is mark the ViewModel up with NonShared, so for example I did a small test, and the WPF demo apps ViewModel looked like this
[ExportViewModel("AboutViewModel")]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class AboutViewModel : ViewModelBase
{
........
}
Jul 9, 2010 at 6:24 AM
Edited Jul 9, 2010 at 6:27 AM

Thx for the solution, that solved the problem.

But still have a problem with the workspace, because it doesn't save the associated instance of the VM and creates every time i switch to that tab a new VM now and cause so that the information of the old instance will be lost. I solved that with a separate object which is passed as dataValue on the constructor of WorkSpaceData. It backup the important things and restore it on construction of the VM.

 

Coordinator
Jul 9, 2010 at 11:23 AM
Edited Jul 9, 2010 at 11:24 AM

HelmutE

Gl;ad that sorted you out. The issue you describe is not something to do with Cinch actually, it is a known issure with the standard WPF TabControl, it recreates the VisualTree from scratch on selection. To see that for youself try and have a single custom attached property on a view and bang some of these views into a standard TabControl and watch it fire the attached DP. Its really really bad, and that is why in CinchV1 I created a TabControl that keeps the loaded items in memory and just shows/hides them rather than trashes the contents.

That said I would like to see your solution, could you send me a small sample to sacha[DOT]barber[AT]gmail[DOT]com

 

I would like to see what you have come up with.

Also how are you finding working with CinchV2?

Coordinator
Jul 9, 2010 at 1:12 PM

Helmut

It appears the problem with the standard Tabcontrol only happens when it is not used in direct mode (ie the contents are bound datatemplates). If you send me a email to address shown in my last post I can send you a sample that shows you how to fix it using a better behaved TabControl, or you could look at the CinchV1 demo app and look for TabControlEx code and TabControlEx style.

 

I have just tried it and it works fine using the CinchV1 demo app and look for TabControlEx code, I can send you a demo if you drop me an email

 

Coordinator
Jul 11, 2010 at 9:37 AM
Helmut if you look at latest source code (and in particular the WPF demo) you will see there is a specialized TabControl which keeps all items in memory (not something the standard WPF TabControl does), so you can use that for WPF. As for SL, as SLs TabControl lacks the same overrides I could not help there, so people will have to think of something themselves. But as I do not offer the same workspace support in Cinch.SL as I do for Cinch.WPF, my thinking is that is ok. Hope that helps you
Jul 12, 2010 at 6:42 AM

Wow really great :) loves Cinch

Coordinator
Jul 12, 2010 at 9:56 AM

There is one small issue I am having where the View is GCd weirdly sometimes, but I am looking at that, and hope to have it fixed very soon

Jul 12, 2010 at 12:33 PM

I had the same problem in my project - but now its solved!  :-)

Thanks.... I love cinch.

 

Your demo app helps a lot. Last week i migrated my old cinch V1 project to v2 - a lot of work because of the new simple command and changed behaviors - but i like it.

i love the new simple command - now its really simple ;-)

... the view model injection and blendability

... the simple behavior usage ....

i am looking forward to your new articles....

best regards

Avidin

Coordinator
Jul 12, 2010 at 2:15 PM

Thanks. Like I say there is one small issue around workspaces that in WPF, but I am working on it, and hope to have it fixed very very soon. Not even sure its a problem yet. Just making sure. Glad you like all the new stuff. I knew it would be hard for people to change, but I think the new way is better.

Jul 12, 2010 at 4:06 PM

I agree with you - cinchV2 is the better way.

I am working on a large bioinformatical project including sql server support and a lot of views/viewmodels.

With V2 i can better organize the stuff than cinchv1. Now popups are easy to use.

 

The migration to v2 produces some small trouble...

 

 I am often using the mediator to notify the mainwindow about status, progress etc.,

but in some cases i got  this error in your ApplicationHelper class:

Cannot perform this operation while dispatcher processing is suspended.

 

Sometimes i don't understand this message - it seems to be a timing problem between view creation and message receiving - sometimes i had an Xaml error in the view. But some xaml errors are difficult to find for me. I got this error in one view yet.

I simply using a try catch block in your helper class – not a nice “solution” but it helps. May be you can include it in your build.

    try {
                Dispatcher.PushFrame(frame);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("DoEvents Error: " + ex.Message);
                //throw;
            }

Do you have any idea what’s happens there.

 

I had to change your lovely openfileservice to support multi file selection.

By the way, could you change the platform target in the cinch.wpf build properties to AnyCPU - it would support 64 bit windows. It was some trouble to find this "error" ;-)

 

Cinch is a nice framework – I can concentrate on my bio stuff – and can use this nice MVVM in my wpf projects.

Coordinator
Jul 12, 2010 at 4:31 PM

Yes I'll change it any CPU and Add that try/catch for you. As far as the message undoubtebly a timing thing, bastards those ones

Coordinator
Jul 23, 2010 at 10:40 AM

Workspace issues all fixed