检测何时选择设计表面上的控件

发布于 2024-10-27 14:07:02 字数 84 浏览 1 评论 0原文

我正在编写一个 Expression Blend 4 扩展,我想检测(在我的扩展中)何时选择设计表面上的控件或元素。有人可以告诉我如何检测它吗?谢谢,蒂姆

I'm writing an Expression Blend 4 Extension and I want to detect (in my extension) when a Control or Element on the design surface is selected. Can someone tell me how I can detect it? Thanks, Tim

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

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

发布评论

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

评论(1

如果没有 2024-11-03 14:07:02

我继续了我的教程编写扩展。当您查看该项目的示例代码时,下面的代码应该很清楚。

当活动文档更改时,将调用下面的第一个方法。此方法处理 IDocumentServiceActiveDocumentChanged 事件。首先,它从调色板注册表中获取TimelinePane的内容。此内容中包含 ActiveSceneViewModel。 ActiveSceneViewModel 是包含活动场景(= 当前正在编辑的 xaml 文件)的视图模型。 ActiveSceneViewModel 包含一组选定的元素,即 ElementSelectionSet。其中有一个事件(Changed),当它被更改时会被触发。处理这个事件。

在此事件处理程序中,您可以在更改后立即访问选择集。

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
}

I've continued a bit on my tutorial on writing extensions. When you look at the sample code of this project the code below should be clear.

The first method below is called when the active document is changed. This method handles the ActiveDocumentChanged event of the IDocumentService. First it gets the content of TimelinePane from the palette registry. In this content lives the ActiveSceneViewModel. The ActiveSceneViewModel is the viewmodel that containse the active scene (= the current xaml file being edited). The ActiveSceneViewModel contains a set of the selected elements, the ElementSelectionSet. Which has an event(Changed) that is fired when it is changed. Handle this event.

In this eventhandler you'll have access to the selection set, directly after it is changed.

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