Detect when a control is selected on a design surface

I am writing an Expression Blend 4 Extension and want to detect (in my extension) when a control or element on a design surface is selected. Can someone tell me how I can detect this? Thanks Tim

+5
source share
1 answer

I continued to read my extension tutorial a bit . When you look at the sample code for this project, the code below should be clear.

The first method below is called when the active document is modified. This method handles the ActiveDocumentChanged IDocumentService event . First, it gets the contents of the TimelinePane from the registry palette. This content contains the ActiveSceneViewModel . ActiveSceneViewModel is a viewmodel that contains the active scene (= current xaml file, editable). ActiveSceneViewModel contains a set of selected items, ElementSelectionSet. You have an event (Changed) that fires when it changes. Handle this event.

In this event handler, you will have access to the selection set immediately after changing it.

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
source

All Articles