Basic CommandParameter binding question (Silverlight)

Topics: Prism v2 - Silverlight 2
May 23, 2009 at 10:46 AM

Hi

I have got the basic PRISM Command pattern working passing in static CommandParameters for a checkbox.

Is there some way I can now bind the CommandParameter to the checkbox's 'Checked' value instead?

The checked attribute is not specifically attached to a property of my model as it is a 'select all' type situation whereby the command action will set an attribute on each child in a collection.

Thanks

Mark

May 26, 2009 at 8:55 PM

Hi Mark,

 

The current version of Silverlight (SL 2.0) does not support Element to Element Binding so you won't be able to bind to the checked value of the Checkbox control. On the other hand, the new beta version of Silverlight (SL 3.0 beta) supports the this kind of bindings: A guide to Silverlight 3 new features.

 

Silverlight 3 is compatible with prism-v2. All features that were available in SL2 can be used with Prism-v2, but some new features might have some limitations. Mariano Converti and Damian Schenkelman have tried it, so you can read about that in the following links:

·         How To: Integrate a Prism v2 application with the Silverlight 3 Navigation Framework

·         Prism 2 & Silverlight 3 Beta Navigation

·         Commands with Attached Behavior for Silverlight 3 DataForm

 

Hope it helps!

 

Matias Bonaventura

http://blogs.southworks.net/matiasb

May 26, 2009 at 9:02 PM

Mark - This just arrived in my inbox - I've only skimmed it but it may help you:

http://www.codeproject.com/Articles/36500/Implementing-RelativeSource-binding-in-Silverlight.aspx

 

Matias - is there any unoffical timeframe for SL3 release? We're not going to market just yet but I've been reluctant to make the jump tto SL3 as I have seen no word as to when it will be available.

Anyone got a best-guess?

May 27, 2009 at 10:00 AM

Thanks for the info. I am using SL3 so that's not a problem.

For anyone else wanting to do this the code is:

<CheckBox x:Name="btnSelectAll" Content="Select All Items"
        cal:Click.CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=IsChecked}"
        cal:Click.Command="{Binding SelectAll}"/>

with of course the viewmodel defining SelectAll method etc.

Thanks again