CanSayHello does not work with DependencyProperty

Topics: Conventions
Feb 29, 2012 at 12:52 PM
Edited Feb 29, 2012 at 12:55 PM

Hi All

Please be patient with me... I'm a newbie to Caliburn.Micro and we're busy evaluating it as a replacement to our current Silverlight MVVM implementation.

I'm working through the samples and so on and found that the x:Name="SayHello" convention of say a button does not get disabled if the CanSayHello property is implemented as a dependency property. It does work if the CanSayHello property is implemented via INPC.
Related link for context: http://caliburnmicro.codeplex.com/wikipage?title=Basic Configuration, Actions and Conventions&referringTitle=Documentation&ProjectName=caliburnmicro

We were hoping to reuse our existing view models since we have various applications for using dependency properties (e.g. there state will be changed by other controls through binding and even animations), so I'm a bit surprised that a basic Silverlight construct like dependency properties doesn't seem to work.

Edit: I can still use binding to disable the button, but would like to leverage the power of the conventions.

In all likelyhood I'm missing something, could anyone enlighten me please?

Thanks,
Jaans

Coordinator
Feb 29, 2012 at 5:07 PM

DependencyProperties on ViewModels would not be considered a good practice, thus it is not supported out of the box.

Feb 29, 2012 at 10:23 PM

Thanks Rob

May I ask why you do not consider it good practise?

Also, if I did want to support it, what changes would I need to make to the source?

Jan 3, 2013 at 12:49 PM

One reason DPs in ViewModels are not good practice is that DependencyProperties within native .NET code, are implemented at the same layer as the control itself.  See this example of a custom control http://wpftutorial.net/HowToCreateACustomControl.html

This means that the DefaultKeyStyleProperty is used to tie the code behind (or rather code aside) to the control.  I say code aside because within .NET base code and custom control creation, the XAML code definitions cannot be double clicked on to get to the code behind.  The XAML is stand alone code and the Property meta data tying the code to the XAML at run time based on folder naming conventions of the XAML being found in the folder, Themes with a name of Generic.XAML.  Wow that was a mouthful.

DependencyProperites must either live in the Code Behind or (Code Aside), in order for those properites to show up in the designer.  If they are put into the ViewModel they just won't show up...  But can they go into the View Model?  Sure, just make sure you know why you are doing that...