将所选项目作为参数发送到视图模型中的方法 [WPF、Caliburn]

发布于 2024-10-08 05:09:10 字数 787 浏览 0 评论 0原文

我有这个问题。我在 WPF 中使用 calibburn micro。在视图中,我有列表框,并且我绑定在视图模型中的事件 MouseDoubleClick 方法上。我想作为参数发送选定的列表框项目。但我不知道该怎么做。

在视图中我有这个:

    <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"/>

在视图模型中我有这个方法:

    public void SendRp(string key)
    {
        MessageBox.Show(key);
    }

任何进展,谢谢。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温馨耳语 2024-10-15 05:09:10

我对 caliburn 不太了解,但我猜你还必须写

Micro:Message.Attach="[MouseDoubleClick]=[Action SendRp(Friends.SelectedItem)]"

一下,你应该省略 SelectedItem="Key" 或使用与 ViewModel 的绑定,如下所示:

SelectedItem="{Binding Key}"

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}"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文