SelectionChanged Event Not Firing

Oct 27, 2009 at 2:22 PM

I am working on an application with the libraries of NodeXL.  I've got a Windows Form application hosting a NodeXLControl through an ElementHost.

In my WPF control, I have coded the SelectionChanged event, but it does not seem to be firing when I change the selection in the control at run time.  I know that the selection is changing, because the vertex and edges are highlighting.

Below are my XAML and C# code:

<UserControl x:Class="BRWEEditor.NodeMap"
    Height="300" Width="300" xmlns:my="clr-namespace:Microsoft.NodeXL.Visualization.Wpf;assembly=Microsoft.NodeXL.Control.Wpf" Name="MapNode">
        <my:NodeXLControl Margin="-1,-1,1,1" Name="nodeXLControl1" ClipToBounds="False" ShowVertexToolTips="False" VertexShape="Square" VertexSelectedColor="Yellow" SelectionChanged="nodeXLControl1_SelectionChanged" />
using System;
using System.Windows.Controls;
using System.Windows.Media;
using Microsoft.NodeXL.Core;
using Microsoft.NodeXL.Visualization.Wpf;

namespace BRWEEditor
    /// <summary>
    /// Interaction logic for NodeMap.xaml
    /// </summary>
    public partial class NodeMap : UserControl
        public NodeMap()

        private void nodeXLControl1_SelectionChanged(object sender, EventArgs e)
            foreach (IVertex ThisVertex in ((NodeXLControl)sender).SelectedVertices)
                ThisVertex.SetValue(ReservedMetadataKeys.PerVertexPrimaryLabelFillColor, Color.FromArgb(255, 255, 255, 0));                

Any suggestions/ideas would be greatly appreciated!



Oct 27, 2009 at 4:14 PM
Edited Oct 27, 2009 at 4:14 PM


The NodeXLControl's SelectionChanged event definitely fires (our Excel template depends on it), so I'm not sure what's going wrong in your case.  As an experiment, can you wire up the event handler in code instead of XAML and see what happens?  In other words, remove the 'SelectionChanged="nodeXLControl1_SelectionChanged"' XML attribute, and in your constructor, insert this:

nodeXLControl1.SelectionChanged += new System.EventHandler(this.nodeXLControl1_SelectionChanged);

-- Tony

Oct 28, 2009 at 1:03 PM

I did that, and now it fires like I would expect.  I'm not sure what is wrong with the WPF/XAML-generated method, but coding it by hand in the Windows Form portion of the project worked fine.  This is my first foray into WPF, so I know nothing about that framework.






Oct 28, 2009 at 5:12 PM

I didn't implement WPF's routed events in NodeXLControl, so you can't hook up the control's events in XAML the way you were trying to do it.  This may change in a future version -- see the "Future Work" section in the control's topic in the NodeXLApi.chm help file.

-- Tony