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.
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.