WPF Programming with MVVM

The files below contain presentation material for Fairfield-Westchester Code Camp 2010

Answers to some questions raised during presentation:

Q: Does MVVM apply to Silverlight?

A: Absolutely. Silverlight may have different set of properties and events, but the same general concepts still apply, including attached behaviors.

Q: When you rename a property in Visual Studio, does refactoring with rename all the bindings?

A: Unfortunately, it will not. You will have to fix the bindings yourself. Also, if you have RaisePropertyChanged("OldName"), you will have to manually modify it to RaisePropertyChanged("OldName").

Q: How do you pass a command parameter to a command?

A: In XAML you can specify parameter such as an enum using CommandParameter property:

            <ContextMenu>
                <MenuItem Header="Left" Command="{Binding ContextCommand}" CommandParameter="{x:Static local:Direction.Left}" />
                <MenuItem Header="Right" Command="{Binding ContextCommand}" CommandParameter="{x:Static local:Direction.Right}" />
                <MenuItem Header="Top" Command="{Binding ContextCommand}" CommandParameter="{x:Static local:Direction.Top}" />
                <MenuItem Header="Bottom" Command="{Binding ContextCommand}" CommandParameter="{x:Static local:Direction.Bottom}" />
            </ContextMenu>

On the view model side you have to define your DelegateCommand class to pass the command parameter to the delegate. Complete sample is here.