Strange behaviour in Visual Studio designer dragging Model onto the canvas

Strange behaviour in Visual Studio designer dragging Model onto the canvas

Old forum URL: forums.lhotka.net/forums/t/9262.aspx


cds posted on Friday, July 23, 2010

Hi Rocky

I have a very strange problem.

I have bought and viewed the MVVM video series (excellent so far). I have the demo project open and it all works fine.

In my own solution I've replicated what is in the demo and it all works fine except....

I have a ViewModel subclass for a ReadOnlyList - I do the BeginRefresh and it all works fine.

But when I drag the Model off the DataSources window, it creates the DataGrid on my User Control. Everything is bound correctly - I have 2 CollectionViewSources in the UserControl.Resources - one for the ViewModel and the other for the Model off the ViewModel - all seems right, and exactly the same as the SLDemo project.

However, when I look at the DataGrid, the ItemsSource is missing. In the SLDemo it has ItemsSource="{Binding" but this isn't done by the designer in my example project.

I can't figure out what the difference is!

Naturally when my ViewModel refreshes, unless I have manually typed the ItemsSource="{Binding}" into the XAML I don't see anything in the grid.

Any ideas on what might be making the Cider designer behave this way? I'm running on the CSLA 4 release now. I've also tried this multiple times in my demo project, but each time with the same result. And I've tried adding a new UserControl in the SLDemo project and it works fine there.

Thanks,

Craig

RockfordLhotka replied on Friday, July 23, 2010

There was a refresh to the Silverlight 4 designer for VS10 after VS10 itself was released. Perhaps you aren't running the final Silverlight designer code?

cds replied on Friday, July 23, 2010

No, I don't think that's the case. I'm running two copies of VS2010 - one on my project and one on the source code from the MVVM videos.

Anyway I completely rebuilt my solution from scratch then it started working properly. Smile Then I added a second ViewModel and it broke again! Sad

So, I don't know what the pattern is - but at least I know what to look out for when it's not working. I guess manually having to add ItemsSource="{Binding}" to the DataGrid isn't too much of a burden.

Cheers,

Craig

RockfordLhotka replied on Saturday, July 24, 2010

The designer does act differently depending on whether there's already some designer code there or not. They add resources and set datacontext values the first time you drag something on. The second time, you are probably dragging into a container, and they set up the bindings a little differently, because there's already a top-level datacontext.

Maybe you are hitting a bug in the designer, or maybe it is just acting differently because you are dragging out several different data sources.

Copyright (c) Marimer LLC