简体   繁体   English

WPF如何从功能区窗口调用用户控制命令

[英]WPF How to call User Control Command from window Ribbon

This is a Dejavù question, I've asked yesterday evening but probably I didn't post it correctly because the question is not on my profile. 这是一个Dejavù问题,我昨天晚上问过,但由于问题不在我的个人资料中,所以我可能未正确发布。 If you find it please don't kill me for the double question. 如果找到它,请不要为双重问题而杀了我。

As stated in the Subject, I'm implementing for the first time in WPF a visual studio like interface, I've read on MSDN the command target and command source article but still I've not been able to find a good sample to explain me the following: If I have my main window with the ribbon and the 4 crud base buttons, Insert, Delete, Save and Undo, then I have several user controls, one for each Table or group of related tables, and I put the Controls in a docking manager creating Tab Like objects in the Main Window, how do I Bind the Ribbon commands so that they are executed against the currently "focused" User control, the one the user is currently seeing? 如主题中所述,我是第一次在WPF中实现一个可视化工作室(如界面),我已经在MSDN上阅读了命令目标和命令源文章,但仍然找不到很好的示例来说明我有以下内容:如果我的主窗口包含功能区和4个基本按钮,即“插入”,“删除”,“保存”和“撤消”,那么我有几个用户控件,每个用户控件用于一个表或一组相关表,并且我将控件在对接管理器中,在主窗口中创建Tab类似对象,我如何绑定功能区命令,以便针对当前“集中”的用户控件(用户当前正在查看的控件)执行它们? Thank you in advance 先感谢您

I have came across the same situation and somehow managed to implement it. 我遇到了同样的情况,并设法实现了它。 Below is my Idea. 以下是我的想法。

  1. Create a IBaseViewModel with Crud commands, 使用Crud命令创建一个IBaseViewModel,
  2. Write separate classes inherited from from BaseViewModel, and make sure they are the DataContext for each UserControl. 编写从BaseViewModel继承的单独的类,并确保它们是每个UserControl的DataContext。
  3. Set Ribbon DataContext from DockingManager's Selected child (i ended up writing attached property for finding Selected child.) 从DockingManager的Selected子项设置Ribbon DataContext(我最终编写了用于查找Selected子项的附加属性。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM