开发者

send selected item as parameter to method in view-model [WPF,Caliburn]

开发者 https://www.devze.com 2023-01-31 05:31 出处:网络
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

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}"
0

精彩评论

暂无评论...
验证码 换一张
取 消