问题描述
我有这个问题.我在WPF中使用caliburn micro.在视图中,我具有列表框,并且绑定了视图模型中的事件MouseDoubleClick方法.我想将选定的列表框项目作为参数发送.但是我不知道怎么做.
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.
鉴于我有这个:
<ListBox Name="Friends"
SelectedItem="Key"
Style="{DynamicResource friendsListStyle}"
Grid.Row="2"
Margin="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);
}
任何进展,谢谢.
推荐答案
我对caliburn不太了解,但我猜想是你必须写
I dont know much about caliburn but my guess is you have to write
Micro:Message.Attach="[MouseDoubleClick]=[Action SendRp(Friends.SelectedItem)]"
您还应该省略SelectedItem="Key"
或使用与ViewModel的绑定,如下所示:
also you should either omit the SelectedItem="Key"
or use a binding to your ViewModel like this:
SelectedItem="{Binding Key}"
如果我由于对caliburn知识的缺乏而完全假冒我的帖子,请提前表示歉意.
sorry in advance if my post is completely bogus due to my lack of caliburn knowledge
这篇关于将选定的项目作为参数发送到视图模型[WPF,Caliburn]中的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!