MVVM light - 从 XAML 在 RelayCommand 中传递多个参数

发布于 2024-10-03 00:12:37 字数 353 浏览 0 评论 0原文

我的视图上有多个 PasswordBox,当我单击按钮时,我想将它们的所有 SecureString 传递到我的视图模型。

我的猜测是,我想用所有 SecureString 填充自定义类的实例,并将该对象作为参数传递给绑定到按钮的 RelayCommand。 如果我只知道如何...

我当前的解决方法的想法:

在按钮的 RelayCommands 操作中:发送一个带有以自定义类作为参数的回调的NotificationMessageAction。 在后面的视图代码中注册该消息,然后使用 SecureString 填充对象,然后借助回调将该对象传递回视图模型。不是很好...

必须有更好的方法在 XAML 中执行此操作,对吗?

I have more than one PasswordBox on my view and I want to pass all their SecureStrings to my view model when I click a button.

My guess is that I want to populate an instance of a custom class with all the SecureStrings and pass that object as a parameter to the RelayCommand bound to the button.
If I only knew how...

My current idea for a work around:

In the RelayCommands action for the button: send out a NotificationMessageAction with a callback taking a custom class as parameter.
Register for that message in the views code behind, and then populate an object with the SecureStrings, and then pass that object back to the view model with the help of the callback. Not very nice...

There must be a better way to do this in XAML, right?

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

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

发布评论

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

评论(1

開玄 2024-10-10 00:12:37

实际上,我认为您想要做的是实现事件处理程序,或者在 PaswordBox 上实现附加行为,将 SecureString 推送到将处理 RelayCommand 操作的同一视图模型对象中的属性。那么你的 RelayCommand 将根本不需要任何参数。

Actually, I think what you want to do is implement event handlers, or an attached behavior on your PaswordBoxes that will push the SecureStrings to properties in the same viewmodel object that will be handling the RelayCommand's action. Then your RelayCommand won't need any parameters at all.

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