views:

831

answers:

1

I have a question concerning Josh Smith's famous demo app on MVVM.

I try building a "real" application around it to learn WPF.

He creates this CommandsList in the MainWindowViewModel containing 2 Commands (create new and view all customers). This list is readonly (why? any particular reason?). I thougt it would be nice to add and remove some commands, depending on the workspace that is currently selected. Like edit or delete a customer when it has the focus and so on.

How would I accomplish this?! Can I just make it a normal list and add commands? Or bind the Commands-View to a commands list of the selected workspace instead of the MainWindow? How? Any other ways? Please share your ideas!

Thank you very much!

+1  A: 

I write an article about defining the commands in the viewmodel and how you can then use all the possibilities of databinding to show your commands.

One of the possibilities mentioned was to

define a filtered version of the command list “local menu commands” for direct use in the view

Something similar is what I think you should do in your situation: write some filtered version of the command list and change it depending on your state.

The article also contains a link to a very simple demo application that shows only how this works so I think it could help you.

DaniCE
Your article seems very detailed and interesting. I will work through it and share my experiences here. Thank you.
MAD9
after long considerations, I will use <a href="http://www.codeproject.com/KB/WPF/VMCommanding.aspx">Josh Smith's approach</a>, because I find it, no offense, easier to understand (this means nothing though, cuz I am pretty a noob).Since you mention it in your article, I set your answer as the accepted answer =) Thank you very much.
MAD9
maybe, the article you mention of Josh Smith is easier to understand because it is closer to the "original" concept of the commands in wpf.The commands in the viewmodel is a construction made on top of that, i maybe everything gets clearer to you if first you read some explanation about the neat wpf commands, for example here:http://www.switchonthecode.com/tutorials/wpf-tutorial-command-bindings-and-custom-commands(and, of course, there is no offense at all)
DaniCE