title: Displaying line series in WPF chart with vb.Net
body: <p>I'm having a rather frustrating time porting some VB.Net winforms code to WPF, and could do with a quick bit of assistance:</p>
  
  <p>In short, I have data that is generated dynamically that I need to plot on a lineseries.  Regardless of what I try, the chart is stubbornly refusing to display my data! I've messed about with just about every combination of .DataContext / .ItemsSource / Bindings / etc. I can find and have had a serious google about, but good VB.Net examples seem to be thin on the ground.  I've clearly missed something "simple"...  any suggestions will be welcomed.</p>
  
  <p>Cut-down code is as follows:</p>
  
  <p>XAML:</p>
  
  <pre><code>    &lt;Window
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" x:Class="MainWindow"
  Title="MainWindow" Height="350" Width="525"&gt;
  &lt;Grid&gt;
  
      &lt;chartingToolkit:Chart x:Name="MyChart" HorizontalAlignment="Left" Margin="10,10,0,0" Title="Chart Title" VerticalAlignment="Top" Height="300" Width="497"&gt;
          &lt;chartingToolkit:LineSeries x:Name="MyLineSeries" DependentValueBinding="{Binding Path=Intensity}"  IndependentValueBinding="{Binding Path=PxNum}" IsSelectionEnabled="True" ItemsSource="{Binding}" &gt;
  
  
              &lt;!-- Vertical axis for Intensity values --&gt;
              &lt;chartingToolkit:LineSeries.DependentRangeAxis&gt;
                  &lt;chartingToolkit:LinearAxis
                                  Orientation="Y"
                                  Title="Intensity"
                                  Minimum="0"
                                  Maximum="65535"
                                  Interval="8000"
                                  ShowGridLines="True"
                      /&gt;
              &lt;/chartingToolkit:LineSeries.DependentRangeAxis&gt;
          &lt;/chartingToolkit:LineSeries&gt;
  
          &lt;chartingToolkit:Chart.Axes&gt;
              &lt;!-- Shared horizontal axis --&gt;
              &lt;chartingToolkit:LinearAxis
                              Orientation="X"
                              Title="Detector px"
                              Interval="64"
                              Minimum="0"
                              Maximum="256"
                              ShowGridLines="True"/&gt;
          &lt;/chartingToolkit:Chart.Axes&gt;
  
      &lt;/chartingToolkit:Chart&gt;
  
  &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>VB:</p>
  
  <pre><code>    Imports System.Collections.ObjectModel
  
      Class MainWindow
  
      Dim Series_Saturation As New ObservableCollection(Of GraphPoint)
  
      Private Sub MainWindow_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
  
  
      Series_Saturation.Add(New GraphPoint() With {.PxNum = 0, .Intensity = 54000}) '    New KeyValuePair(Of Int32, Int32)(0, 54000))
      Series_Saturation.Add(New GraphPoint() With {.PxNum = 200, .Intensity = 54000}) '   New KeyValuePair(Of Int32, Int32)(nPX, 54000))
  
      MyLineSeries.DataContext = Series_Saturation
  End Sub
  
  End Class
  
  
  Public Class GraphPoint
  
      Public Property PxNum As Long
      Public Property Intensity As Long
  
  End Class
  </code></pre>