WP7 attached method parameter issue

Sep 9, 2010 at 3:16 PM


I am trying to get the selected Item from a ListBox in the View so that I can feed the SelectedItem to ViewModel to act on the selection.
I have an action attached to the "SelectionChanged" event on a ListBox on WP7.
 When the action method has no parameter there are no issues. 
cal:Message.Attach="[Event SelectionChanged] = [Action ShowArea]">

When I add constant parameter like 1 or 2 and have that method accept an int, there are no issues.

cal:Message.Attach="[Event SelectionChanged] = [Action ShowAreaEx(1)]"

But when I have something like below.


		<ListBox x:Name="SubAreas"
				  cal:Message.Attach="[Event SelectionChanged] = [Action ShowSubArea(SubAreas.SelectedItem)]">


The App breaks in Parser.cs at


            var expression = (BindingExpression)BindingOperations.SetBinding(parameter, Parameter.ValueProperty, binding);
with the exception
Target must be a FrameworkElement or a CollectionViewSource.

The target in this case was the ListBox.
I have verified that the ListBox is derives from FrameworkElement. This code was working in WPF when I used ListView instead of the ListBox.
The problem is with the parameter passed.
Am I doing something wrong or is there a better way of achieving what I am trying to do?
Thanks a bunch.


Sep 9, 2010 at 3:36 PM

Please see the documentation on actions: http://caliburnmicro.codeplex.com/wikipage?title=All%20About%20Actions&referringTitle=Documentation Footnote #3

Sep 9, 2010 at 3:37 PM

I recommend that you solve this by using normal databinding of the SelectedItem property.