开发者

Detect when a control on design surface is selected

开发者 https://www.devze.com 2023-02-20 17:27 出处:网络
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 i开发者_如何学JAVAs selected. Can someone tell me how I can detect i

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 i开发者_如何学JAVAs selected. Can someone tell me how I can detect it? Thanks, Tim


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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号