Imports System.Net Imports System.Windows Imports System.Windows.Controls Imports System.Windows.Documents Imports System.Windows.Ink Imports System.Windows.Input Imports System.Windows.Media Imports System.Windows.Media.Animation Imports System.Windows.Shapes Imports C1.WPF.C1Chart Public Class AlarmZone Inherits XYDataSeries #Region "constructor" Public Sub New() AddHandler Me.LayoutUpdated, AddressOf AlarmZone_LayoutUpdated Me.ChartType = C1.WPF.C1Chart.ChartType.PolygonFilled UpdateLegend() Update() End Sub #End Region #Region "members" Private _chart As C1Chart Public Property Chart() As C1Chart Get Return _chart End Get Set(value As C1Chart) _chart = value End Set End Property Private _lowerExtent As System.Nullable(Of Double) = Nothing Public Property LowerExtent() As System.Nullable(Of Double) Get Return _lowerExtent End Get Set(value As System.Nullable(Of Double)) _lowerExtent = value Update() End Set End Property Private _upperExtent As System.Nullable(Of Double) = Nothing Public Property UpperExtent() As System.Nullable(Of Double) Get Return _upperExtent End Get Set(value As System.Nullable(Of Double)) _upperExtent = value Update() End Set End Property Private _near As System.Nullable(Of Double) = Nothing Public Property Near() As System.Nullable(Of Double) Get Return _near End Get Set(value As System.Nullable(Of Double)) _near = value Update() End Set End Property Private _far As System.Nullable(Of Double) = Nothing Public Property Far() As System.Nullable(Of Double) Get Return _far End Get Set(value As System.Nullable(Of Double)) _far = value Update() End Set End Property Private _showInLegend As Boolean = False Public Property ShowInLegend() As Boolean Get Return _showInLegend End Get Set(value As Boolean) _showInLegend = value UpdateLegend() End Set End Property #End Region #Region "implementation" Public Sub Update() If _near IsNot Nothing AndAlso _far IsNot Nothing Then Me.XValues = New DoubleCollection() Me.XValues.Add(CDbl(_near)) Me.XValues.Add(CDbl(_far)) Me.XValues.Add(CDbl(_far)) Me.XValues.Add(CDbl(_near)) End If If _lowerExtent IsNot Nothing AndAlso _upperExtent IsNot Nothing Then Me.Values = New DoubleCollection() Me.Values.Add(CDbl(_lowerExtent)) Me.Values.Add(CDbl(_lowerExtent)) Me.Values.Add(CDbl(_upperExtent)) Me.Values.Add(CDbl(_upperExtent)) End If End Sub Public Sub UpdateLegend() If _showInLegend Then Me.Display = SeriesDisplay.SkipNaN Else Me.Display = SeriesDisplay.HideLegend End If End Sub Private Sub chart_LayoutUpdated(sender As Object, e As EventArgs) If Chart IsNot Nothing Then If Chart.View IsNot Nothing Then ' if extent is null, set to axis bounds If _near Is Nothing Then _near = Chart.View.AxisX.ActualMin Update() End If If _far Is Nothing Then _far = Chart.View.AxisX.ActualMax Update() End If If _upperExtent Is Nothing Then _upperExtent = Chart.View.AxisY.ActualMax Update() End If If _lowerExtent Is Nothing Then _lowerExtent = Chart.View.AxisY.ActualMin Update() End If End If End If End Sub #End Region Private Sub AlarmZone_LayoutUpdated(sender As Object, e As EventArgs) If Me.Parent IsNot Nothing AndAlso Me.Chart Is Nothing Then Dim c As Canvas = TryCast(Me.Parent, Canvas) If c IsNot Nothing Then Dim cv As Canvas = TryCast(c.Parent, Canvas) If cv IsNot Nothing Then Dim b As Border = TryCast(cv.Parent, Border) If b IsNot Nothing Then Dim g As Grid = TryCast(b.Parent, Grid) If g IsNot Nothing Then Dim chart As C1Chart = TryCast(g.Parent, C1Chart) If chart IsNot Nothing Then Me.Chart = chart AddHandler Me.Chart.LayoutUpdated, AddressOf chart_LayoutUpdated End If End If End If End If End If End If End Sub End Class