通过查询字符串将枚举值传递给 CaliburnMicro 视图模型

发布于 2024-11-05 07:05:45 字数 688 浏览 1 评论 0原文

我是 Caliburn Micro 的新手,正在尝试其 WP7 实现。我想将枚举值从一个虚拟机传递到另一个虚拟机,但我必须遗漏一些明显的东西:我尝试传递其名称及其数值,但目标虚拟机始终获取默认值(对应于 0)。

我的场景更详细:假设我有一个虚拟机,其属性公开了枚举值。假设枚举是 ProductFamily { Hardware, Software };我有一个按钮,可以打开另一个带有底层虚拟机的屏幕,该屏幕应根据所选系列显示产品列表。因此,VM 在其构造函数中接收的 INavigationService 实例上调用 Navigate,如下所示:(

_navigation.Navigate("MyView.xaml?Family=" + _nFamily, UriKind.RelativeOrAbsolute);

此代码传递名称,但我也尝试使用 (int)_nFamily)。现在,我在目标 VM 中有一个相应的 Family 属性,例如

public ProductFamily Family { get { ... } set { ... } }

,如果我在属性设置器中放置一个断点,我可以看到它被 CM 调用,但接收到的值对应于默认值(0,例如上面示例中的硬件) ,而我正在等待另一个。我可以确认在构建导航查询字符串时传递了正确的值。那么,目标虚拟机如何获得错误的值呢?

感谢大家

I'm new to Caliburn Micro and I'm experimenting with its WP7 implementation. I'd like to pass the value of an enum from one VM to another but I must be missing something obvious: I tried to pass its name and its numeric value, but the target VM always gets the default value (corresponding to 0).

My scenario in more detail: say I have a VM with a property exposing an enum value. Say the enum is ProductFamily { Hardware, Software }; I have a button which opens another screen with an underlying VM which should show a list of products according to the family chosen. So the VM calls Navigate on the INavigationService instance received in its constructor, like:

_navigation.Navigate("MyView.xaml?Family=" + _nFamily, UriKind.RelativeOrAbsolute);

(this code passes the name, but I tried also with (int)_nFamily). Now, I have a corresponding Family property in the target VM, e.g.

public ProductFamily Family { get { ... } set { ... } }

if I place a breakpoint in the property setter I can see it is called by CM, but the received value corresponds to the default (0, say Hardware in the sample above), while I'm expecting another one. I can confirm the right value is passed when building the query string for navigation. So, how happens that the target VM gets an incorrect value?

Thanks to all

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

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

发布评论

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

评论(1

杯别 2024-11-12 07:05:45

听起来这可能是值转换逻辑中的一个错误。您能否在项目网站上针对该问题创建一个票证并附上一个演示该问题的简单示例?如果是这样,我可能可以相对较快地解决这个问题。

It sounds like this may be a bug in the value conversion logic. Can you create a ticket for the issue on the project site and attach a simple sample that demonstrates the problem? If so, I can probably get this fixed relatively quickly.

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