视图之间的通信

发布于 2024-09-26 02:03:28 字数 190 浏览 0 评论 0原文

我对如何设置视图之间的消息传递有点困惑。我正在做的是在我的主页中使用 radtabcontrol。此后启动的每个视图都绑定到一个新选项卡。当需要终止选项卡时,即用户请求关闭或不再需要它时,我需要与主页通信,以便它可以终止视图并关闭选项卡。

有人可以帮我找到教程或者提供使用 Messenger 和 RelayCommand 来执行此操作的示例代码吗?

I am abit confused about how to setup the messaging between views. What I am doing is using a radtabcontrol in my mainpage. Each view that is launched after that is bound to a new tab. When the tab needs to be terminated, i.e. user requests a close or it is no longer required, I need to communicate back to the mainpage so it can terminate the view and close the tab.

Can someone help me find a tutorial or perhaps provide sample code using Messenger and RelayCommand to do this?

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

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

发布评论

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

评论(1

扛起拖把扫天下 2024-10-03 02:03:28

在 MainPage(或其他)的构造函数中:

Messenger.Default.Register<string>(this, MessageReceived);

MessageReceived 方法(也在 MainPage 中):

private void MessageReceived(string message)
{
    if (message == "SomeTabWasClosed")
    {
        //Do the necessary clean-up
    }
}

然后,当您需要发送消息时(可能在您的选项卡视图或其 ViewModel 中):

Messenger.Default.Send("SomeTabWasClosed");

In the constructor of your MainPage (or whatever):

Messenger.Default.Register<string>(this, MessageReceived);

The MessageReceived method (also in MainPage):

private void MessageReceived(string message)
{
    if (message == "SomeTabWasClosed")
    {
        //Do the necessary clean-up
    }
}

Then when you need to send the message (maybe in your tab Views or their ViewModels):

Messenger.Default.Send("SomeTabWasClosed");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文