Problem with ViewModel visability in Expression Blend

Problem with ViewModel visability in Expression Blend

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


cds posted on Saturday, October 02, 2010

Hi Rocky

I'm using 4.0.1 and have a problem getting my ViewModel to show up correctly in Expression Blend (4).

I've also reproduced my problem with the MVVM videos demo source and it relates to subclassing BusinessBase<T> - i.e. inserting my own class into the CSLA class hierarchy.

In the MVVM video demo there's the EmployeeEdit class, which is a subclass of BusinessBase<EmployeeEdit>.

The EmployeeViewModel is defined as:

public class EmployeeViewModel : ViewModel<EmployeeEdit>

When I open EditEimployee.xaml in Expression Blend it all works fine. In the Data pane, I see the Data Context as being List_ExmployeeViewModel with all the properties and methods (e.g. AddNew, CanAddNew) and the Model property and all its properties.

However, when I insert a custom base class:

[Serializable]

public class MyBusinessBase<T> : BusinessBase<T> where T: BusinessBase<T> { }

then change the EmployeeEdit to:

[Serializable]

public class EmployeeEdit : MyBusinessBase<EmployeeEdit>

Then rebuild the solution and then open up EmployeeEdit.xaml in Expression Blend, the Data Context in the Data pane doesn't show the ViewModel properly. All I see it List_EmployeeViewModel, then 5 methods - AddNew, Cancel, Delete, Remove, and Save.

Can you reproduce this and figure out what is going wrong? Initially this happened on my own project, then I tried it out on the SLDemo.sln and got the same result. It's a bit of a pain not being able to access the ViewModel properties in Blend!

Thanks,

Craig

 

cds replied on Wednesday, October 06, 2010

Bump!

Does anybody else see this, or is it just me?

cds replied on Friday, October 08, 2010

Talking to myself...

But, I did some more experimentation and discovered that it seems to be related to the CollectionViewSource. If I remove this, and have my ViewModel directly as a resource, and then connect my DataContext to that it all works fine.

So, I'm thinking that the automatically created CollectionViewSource in the VS2010 designer is maybe a bit flakey, and maybe manually adding the ViewModel as a resource is the better way to go. From what I've found, building a complex view, i.e. with lots of fields and binding is much more productive in Expression Blend than in the VS2010 designer.

RockfordLhotka replied on Friday, October 08, 2010

VS10 and Blend don't use the same approach when creating XAML for binding, that's true.

I would expect the CVS to work though, because they are decorated with a d: element that should tell Blend what data type to use.

However, it is possible that Blend is trying to directly create an instance of that type - of your viewmodel - at design time. If that's true, there could be something blocking Blend from successfully creating the type.

Copyright (c) Marimer LLC