send selected item as parameter to method in view-model [WPF,Caliburn]
I have this problem. I use caliburn micro in WPF. In view I have listbox, and I bind on event MouseDoubleClick method in view-model. I would like send as parameter selected listbox item. But I don’t know how do it.
in view I have this:
<ListBox Name="Friends"
SelectedItem="Key"
Style="{DynamicResource friendsListStyle}"
Grid.Row="2"
Margin="开发者_JAVA百科4,4,4,4"
Micro:Message.Attach="[MouseDoubleClick]=[Action SendRp(Key)]"
PreviewMouseRightButtonUp="ListBox_PreviewMouseRightButtonUp"
PreviewMouseRightButtonDown="ListBox_PreviewMouseRightButtonDown"
MouseRightButtonDown="FriendsListBoxMouseRightButtonDown"/>
In view model I have this method:
public void SendRp(string key)
{
MessageBox.Show(key);
}
Any advance, thank.
I dont know much about caliburn but my guess is you have to write
Micro:Message.Attach="[MouseDoubleClick]=[Action SendRp(Friends.SelectedItem)]"
also you should either omit the SelectedItem="Key"
or use a binding to your ViewModel like this:
SelectedItem="{Binding Key}"
精彩评论