WPF VB.NET application

Oystein Bjorke 10 lat temu 0
This discussion was imported from CodePlex

Morisse wrote at 2013-08-15 10:11:

Hello,
Thank for your free code. It's seem to be very beautiful.
I've to make an application for an hydraulic bench. It's write under vb.net 2012 WPF.
I've not found any example under vb.net.
I try this :
xaml.vb
Private Sub Window_SourceInitialized_1(sender As Object, e As EventArgs)
    Dim Mesures As New ObservableCollection(Of Mesure)

    For j As Integer = 0 To 25
        Dim Mes As New Mesure
        Mes.Temps = 10 * j
        Mes.Value = 2 * j
        Mes.Maximum = 2 * j + 1
        Mes.Maximum = 2 * j - 1
        Mesures.Add(Mes)
    Next j

    Courb.DataContext = Mesures
End Sub
XAML
<Window x:Class="Fene_Courbe"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:oxy="clr-namespace:OxyPlot.Wpf;assembly=OxyPlot.Wpf"
      Title="COURBES" Height="600" Width="800" Closing="Window_Closing_1" Topmost="True" SourceInitialized="Window_SourceInitialized_1" ContentRendered="Window_ContentRendered_1">

    <Grid>
    <oxy:Plot x:Name="Courb" Title="Courbes" LegendPlacement="Outside" LegendPosition="RightTop" LegendOrientation="Vertical">
        <oxy:Plot.Series>
            <oxy:LineSeries x:Name="CPR1" DataContext="Mesures" Title="PR1"  DataFieldX="Temps" DataFieldY="Value"  ItemsSource="{Binding Items}" StrokeThickness="2" Color="Red" ></oxy:LineSeries>
            <oxy:LineSeries x:Name="CMax" DataContext="Mesures"  Title="Max"  DataFieldX="Temps" DataFieldY="Maximum"  ItemsSource="{Binding Items}" StrokeThickness="2"  Color="Green" ></oxy:LineSeries>
            <oxy:LineSeries x:Name="CMin" DataContext="Mesures"  Title="Min"  DataFieldX="Temps" DataFieldY="Minimum"  ItemsSource="{Binding Items}" StrokeThickness="2"  Color="Violet" ></oxy:LineSeries>
        </oxy:Plot.Series>
    </oxy:Plot>
</Grid>
</Window>

I have a frame with axis and legends for the 3 curves, but no curve.
1- Is anyone can help me ?
2- Can i use also data from a dataset ?
3- Where can i find an vb.net WPF example ?

Thanks by advance
Laurent

objo wrote at 2013-08-15 16:41:

Sorry, there are no VB.NET examples here, I have no experience with VB.
I have not tried with a DataSet yet, but it would be interesting to see if that works! Will add an example (in C#) later.

Morisse wrote at 2013-08-15 19:42:

Thanks for answer,

i continue my tries...

Laurent

Morisse wrote at 2013-08-19 15:56:

Find, i've find. It's very fun and very easy. Thank a lot for this library.

I give you my vb code

Public Class Mesure
    Implements INotifyPropertyChanged

    Private _Temps As Double
    Private _Mesure1 As Double
    Private _Mesure2 As Double
    Private _Mesure3 As Double

    Public Sub New()
        _Temps = 0.0
        _Mesure1 = 0.0
        _Mesure2 = 0.0
        _Mesure3 = 0.0
    End Sub

    Public Overrides Function ToString() As String
        Return Format(_Temps, "{0:##0.00}") & " " & Format(_Mesure1, "{1:# ##0.00}") & " " & Format(_Mesure2, "{2:# ##0.00}") & " " & Format(_Mesure3, "{3:# ##0.00}") 
    End Function

    Private Sub NotifyPropertyChanged(<CallerMemberName()> Optional ByVal propertyName As String = Nothing)
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
    End Sub

    Public Property Temps() As Double
        Get
            Return _Temps
        End Get

        Set(ByVal value As Double)
            _Temps = value
            NotifyPropertyChanged()
        End Set
    End Property
    Public Property Mesure1() As Double
        Get
            Return _Mesure1
        End Get

        Set(ByVal value As Double)
            _Mesure1 = value
            NotifyPropertyChanged()
        End Set
    End Property
    Public Property Mesure2() As Double
        Get
            Return _Mesure2
        End Get

        Set(ByVal value As Double)
            _Mesure2 = value
            NotifyPropertyChanged()
        End Set
    End Property
    Public Property Mesure3() As Double
        Get
            Return _Mesure3
        End Get

        Set(ByVal value As Double)
            _Mesure3 = value
            NotifyPropertyChanged()
        End Set
    End Property

    Public Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged
End Class
MainWindow.xaml.vb
  Public Mesures As New Collection(Of Mesure)


.....
  For k As Double = 0 To 1 Step 0.00001
    Mesures.Add(New Mesure With {.Temps = k, .Mesure1 = Sin(15 * k) * 500, .Mesure2 = Cos(10 * k) * 250, .Mesure3 = Sin(8 * k) * 100)
  Next k
......
Fene_Courbe.xaml

<Window x:Class="Fene_Courbe"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="COURBES" Height="600" Width="800" Closing="Window_Closing_1" Topmost="True"
    xmlns:oxy="clr-namespace:OxyPlot;assembly=OxyPlot"
    xmlns:oxywpf="clr-namespace:OxyPlot.Wpf;assembly=OxyPlot.Wpf" SourceInitialized="Window_SourceInitialized_1">
<Grid>
    <oxywpf:Plot x:Name="Courbes" Title="Courbes" Background="Beige">
        <oxywpf:LineSeries x:Name="PR1" Color="Red" Title="PR1" DataFieldX="Temps" DataFieldY="Mesure1" ItemsSource="{Binding Mesures}" ></oxywpf:LineSeries>
        <oxywpf:LineSeries x:Name="PR2" Color="Blue"  Title="PR2" DataFieldX="Temps" DataFieldY="Mesure2" ItemsSource="{Binding Mesures}" ></oxywpf:LineSeries>
        <oxywpf:LineSeries x:Name="DB1" Color="Green"  Title="DB1" DataFieldX="Temps" DataFieldY="Mesure3" ItemsSource="{Binding Mesures}" ></oxywpf:LineSeries>
    </oxywpf:Plot>
</Grid>
</Window>



Fene_Courbe.xaml.vb

Imports OxyPlot
Imports OxyPlot.Series
Imports System.Collections
Imports System.Collections.Generic
Imports System.Linq
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Imaging
Imports System.Windows.Navigation
Imports System.Windows.Shapes

Public Class Fene_Courbe
Private Sub Window_SourceInitialized_1(sender As Object, e As EventArgs)
    Courbes.Series().Item(0).ItemsSource = Mesures
    Courbes.Series().Item(1).ItemsSource = Mesures
    Courbes.Series().Item(2).ItemsSource = Mesures
End Sub
End Class