How to bind to ViewModel's CanAddNew property?

How to bind to ViewModel's CanAddNew property?

Old forum URL:

xc_lw posted on Wednesday, January 04, 2012

I'm using MVVM+CSLA4+BXF for SilverLight.

In the xaml file I create a CollectionViewSource

<CollectionViewSource x:Key="viewSourceEntry" d:DesignSource="{d:DesignInstance client:EapUserListViewModel, CreateList=True}" />

And I use the follow statement to show a view:

Bxf.Shell.Instance.ShowView(viewName, bindingResourceKey, model,null)

the model is an instance of ViewModel<T>'s derived class-->EapUserListViewModel, and I bind main Grid like this:

<Grid x:Name="Layout" DataContext="{StaticResource viewSourceEntry}"></Grid>

In the Grid I have some buttons, and I bind these buttons' IsEnabled property to CanXXX property. But the CanAddNew property is not effictived.

When I diagnose the code I found that the Grid's DataContext's type isn't an EapUserListViewModel instance, but a System.Windows.Data.ListCollectionView


In EapUserListViewModel I override the CanAddNew,CanCancel,CanDelete,CanSave property and set breakpoint in each get method. I found when the view showing, all breakpoint can be hit except the CanAddNew's get method.

So the btnAddNew always enabled. How to resolve the problem?



Copyright (c) Marimer LLC