使用 Caliburn micro 的动态菜单
我在我的 WPF 项目中使用 Caliburn micro。静态菜单很容易与 Caliburn 绑定
<Menu Grid.Row="0" IsMainMenu="True">
<MenuItem Header="_File">
<MenuItem x:Name="OpenScript" Header="_Open script"/>
</MenuItem>
<MenuItem Header="_Script">
<MenuItem x:Name="RunScript" Header="_Run script" />
<MenuItem x:Name="StopScript" Header="_Stop script" />
</MenuItem>
<MenuItem Header="S_ettings">
<MenuItem x:Name="Plugins" Header="_Plugins">...Clickable children here</MenuItem>
</MenuItem>
</Menu>
。名称绑定到模型上的方法,但是对于您在上面看到的插件菜单,我们需要绑定 PluginViewModel 的集合。然后,当您单击插件时,我想要一个 Caliburn 操作方法在菜单视图模型上触发(您现在可以从中产生返回 IResults 的类型)..这可能吗?
这个问题是针对这个开源项目的 https://github.com/AndersMalmgren/FreePIE
编辑:忘记提及我已经解决了绑定部分,
public BindableCollection<PluginMenuViewModel> Plugins { get; set; }
但我不知道如何听模型的点击声
I use Caliburn micro for my WPF Project. Static menus are easy to bind with Caliburn
<Menu Grid.Row="0" IsMainMenu="True">
<MenuItem Header="_File">
<MenuItem x:Name="OpenScript" Header="_Open script"/>
</MenuItem>
<MenuItem Header="_Script">
<MenuItem x:Name="RunScript" Header="_Run script" />
<MenuItem x:Name="StopScript" Header="_Stop script" />
</MenuItem>
<MenuItem Header="S_ettings">
<MenuItem x:Name="Plugins" Header="_Plugins">...Clickable children here</MenuItem>
</MenuItem>
</Menu>
The names are bound to methods on the model, but for the Plugins menu that you see above we need to bind against a collection of PluginViewModel.. Then when you click a plugin i want a Caliburn action method to trigger on the menu view model (You now the kind that you can yield reuturn IResults from).. Is this possible?
This question is for this open source project
https://github.com/AndersMalmgren/FreePIE
edit: Forgot to mentioned that i have solved the binding part,
public BindableCollection<PluginMenuViewModel> Plugins { get; set; }
But i do not know how to listen to the click from the model
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最好的方法是添加您自己的消息绑定器,
然后您可以像这样从 xaml 使用它
The best way is to add your own message binder
You can then use it from xaml like this
(抱歉我的英语不好)
您可以使用语法(在 XAML 上)在 VM 上调用特定方法:
这将调用 VM 上的
ItemClick
方法,并将有界项本身作为参数传递。如果这是一个具有执行方法的“PluginItem”(就像通常一样),则在该方法中您只需调用它:
您可以在此处阅读有关操作的更多信息:http://caliburnmicro.codeplex.com/wikipage?title=All%20About%20Actions&referringTitle=文档
(sorry for my bad english)
You can call a especific method on your VM using the syntax (on your XAML):
This will call a
ItemClick
method on the VM passing the bounded item itself as parameter.If this is a "PluginItem" with an execute method (like normally is), inside that method you just need to call it:
You can read more about Actions here: http://caliburnmicro.codeplex.com/wikipage?title=All%20About%20Actions&referringTitle=Documentation