Invalid binding to DelegateCommand does not throw

Topics: Prism v2 - Silverlight 2
Sep 21, 2009 at 9:56 PM
Edited Sep 21, 2009 at 9:56 PM


I have a button which is bound to a delegate command:

<Button Name="myButton" Content="Test" cmd:Click.Command="{Binding MyCommand}"></Button>

I notice that there is no exception if MyCommand does not exist (or mispelled etc).

I would say that this policy is bug prone. Isn't it?

Sep 22, 2009 at 8:20 AM

Yes, it might be better to detect if it is in DEBUG mode and change how it deals with these. However, I noticed that if you are running with VS2008, the output window will log this missing information so you can look there to see if there were any name mismatches. Not great but something to use.

Sep 22, 2009 at 8:39 AM

I am running VS2008, I have msbuild log level set to Normal but I don't see anything in output window.

Hmmm... I think the problem is the way I'm defining the binding. I'm using code behind my view: this.DataContext = this.viewModel;

So there is not way that the designer could know about the error. Right?

Sep 22, 2009 at 4:37 PM

There is a way for the designer to know BUT that is not something they implemented. The parts I mentioned was not in the build logs but in the debug logs as it is running. It will give you the information as you load the controls while testing so you can at least see that there is a problem finding something. This is useful for example in databinding in the DataGrid column template.

Sep 24, 2009 at 10:35 PM

This is by design.  All of WPF databinding works like this.  It's to make the views more flexible in certain situations and makes scenarios like designing your views using Expression Blend easier.  It makes the same view work for multiple data contexts with a minimum of problems.