Apr 13, 2010 at 11:07 AM

Hey Tony and others,

I want to use the NodeXL control with a MVVM (viewmodel) pattern. Is there a way I can populate the control with databinding? And if not, can I build the control in the viewmodel and add it to an itemscontrol (if yes, please help, I don't know how)?



Apr 13, 2010 at 6:56 PM
Edited Apr 13, 2010 at 7:06 PM


You can use XAML to insert a NodeXLControl into a window, although you can't set the control's properties or populate the control in XAML.  I don't know how data binding would work, given that the control has two dependent collections that must be populated.  So you must populate the control manually.  If you need an example of how this is done, please see the NodeXLControl Class topic in the NodeXLApi.chm help file that is included in the source code and the Class Libraries downloads.

The NodeXLControl is a UIElement, and thus can be used as an item in any of WPF's ItemsControl controls.  Here is XAML for inserting a NodeXLControl and a Button into a ListBox, for example:

<Window x:Class="WpfApplication1.Window1"
    Title="Window1" Height="300" Width="300" Loaded="Window_Loaded">
        <ListBox Margin="39,38,61,57" Name="listBox1">
        <my:NodeXLControl Margin="115,106,-115,-106" Name="nodeXLControl1" xmlns:my="clr-namespace:Microsoft.NodeXL.Visualization.Wpf;assembly=Microsoft.NodeXL.Control.Wpf" />
        <Button Height="23" HorizontalAlignment="Left" Margin="42,12,0,0" Name="button1" VerticalAlignment="Top" Width="75">Button</Button>

To populate the NodeXLControl, you must implement the Window_Loaded() method specified in the XAML.  That method will look similar to the sample code in the NodeXLApi.chm help file.

-- Tony

Apr 13, 2010 at 8:26 PM


Thanks for you reply! Maybe I was not clear enough, but can I do something like

<Dockpanel Children="{Binding MyControls}" /> And in code behind something like ControlCollection MyControls; MyControls.Add(MyNodeXL); ? If that is possible I can pass a control from ViewModel to View.

Thanks in advance.



Apr 14, 2010 at 1:52 AM

If you're asking whether you can simultaneously use databinding and procedural code to populate the same target, then I don't know the answer.  In Windows Forms I know it was either one or the other, and an exception would be thrown if you tried to do both, but I don't know about WPF.  You might just try it and see what happens.  Also check out the BindingOperations.ClearBinding() method.

-- Tony 

Oct 26, 2011 at 5:10 PM

Hi Tony,

I decided to add to this thread (even though it's old) because my question deals with MVVM as well

I would like to add a NodeXLControl in XAML, and bind to its Graph and Layout properties:

<nxlctrl:NodeXLControl DataContext="{Binding GraphicalView}"
                                   MinHeight="100" MinWidth="500" Height="Auto" Width="Auto"
                                   HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                                   EdgeColor="Gray" EdgeWidth="2" EdgeRelativeArrowSize="3.5"
                                   ShowVertexToolTips="True" VertexSelectedColor="Magenta"
                                   Layout="{Binding Layout}"
                                   Graph="{Binding Graph}">

However, the Graph and Layout properties of the control weren't implemented as DependencyProperty, so they can't be bound in XAML.  Is there any thought about changing these to be DependencyProperty so we can bind to them?


Oct 27, 2011 at 5:57 AM

That's probably not something that will get done in the near future, because it's not needed by our own application and we have limited resources for adding features and doing all the required testing.  If it's something you really need, you can download the NodeXL source code and modify the NodeXLControl class yourself.  You can find the latest "NodeXL Source Code" release under "Other Downloads" at http://nodexl.codeplex.com/releases.  (We do not use the Source Code tab in CodePlex.)

-- Tony