I'm having a rather frustrating time porting some VB.Net winforms code to WPF, and could do with a quick bit of assistance:
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.
Cut-down code is as follows:
XAML:
<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">
<Grid>
<chartingToolkit:Chart x:Name="MyChart" HorizontalAlignment="Left" Margin="10,10,0,0" Title="Chart Title" VerticalAlignment="Top" Height="300" Width="497">
<chartingToolkit:LineSeries x:Name="MyLineSeries" DependentValueBinding="{Binding Path=Intensity}" IndependentValueBinding="{Binding Path=PxNum}" IsSelectionEnabled="True" ItemsSource="{Binding}" >
<!-- Vertical axis for Intensity values -->
<chartingToolkit:LineSeries.DependentRangeAxis>
<chartingToolkit:LinearAxis
Orientation="Y"
Title="Intensity"
Minimum="0"
Maximum="65535"
Interval="8000"
ShowGridLines="True"
/>
</chartingToolkit:LineSeries.DependentRangeAxis>
</chartingToolkit:LineSeries>
<chartingToolkit:Chart.Axes>
<!-- Shared horizontal axis -->
<chartingToolkit:LinearAxis
Orientation="X"
Title="Detector px"
Interval="64"
Minimum="0"
Maximum="256"
ShowGridLines="True"/>
</chartingToolkit:Chart.Axes>
</chartingToolkit:Chart>
</Grid>
</Window>
VB:
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