我正在编写一个 Expression Blend 4 扩展,我想检测(在我的扩展中)何时选择了设计图面上的控件或元素。有人可以告诉我如何检测它吗?谢谢,提姆
最佳答案
我在 my tutorial on writing extensions 上继续了一点.当您查看此项目的示例代码时,下面的代码应该很清楚。
下面的第一个方法在事件文档改变时被调用。此方法处理 IDocumentService 的 ActiveDocumentChanged 事件。首先,它从调色板注册表中获取 TimelinePane 的内容。在此内容中存在 ActiveSceneViewModel。 ActiveSceneViewModel 是包含事件场景(= 当前正在编辑的 xaml 文件)的 View 模型。 ActiveSceneViewModel 包含一组选定元素,即 ElementSelectionSet。其中有一个事件(已更改)在更改时触发。处理这个事件。
在此事件处理程序中,您可以在更改后直接访问选择集。
private void ActiveDocumentChanged(object sender, DocumentChangedEventArgs e)
{
var timelinePane =
(TimelinePane)WindowService.PaletteRegistry["Designer_TimelinePane"].Content;
_activeSceneViewModel = timelinePane.ActiveSceneViewModel;
_activeSceneViewModel.ElementSelectionSet.Changed +=
new System.EventHandler(ElementSelectionSet_Changed);
//some other goes here....
}
void ElementSelectionSet_Changed(object sender, System.EventArgs e)
{
SceneElementSelectionSet selectionSet
= sender as SceneElementSelectionSet;
// get the selected elements from the selection set
}
关于c# - 检测何时选择了设计表面上的控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5472879/