Imports System.Net
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Shapes

Namespace ConditionalFormatting
	Partial Public Class MainPage
		Inherits UserControl
		Public Sub New()
			InitializeComponent()

			_flex.ItemsSource = Product.GetProducts(200)
		End Sub
	End Class

	Public Class ForegroundConverter
        Implements System.Windows.Data.IValueConverter

        Private Shared _brBlack As New SolidColorBrush(Colors.Black)
        Private Shared _brRed As New SolidColorBrush(Colors.Red)
        Private Shared _brGreen As New SolidColorBrush(Colors.Green)

        Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
            Dim range = CType(parameter, Point)
            Dim val As Double = CDbl(value)
            Return If(val < range.X, _brRed, If(val > range.Y, _brGreen, _brBlack))
        End Function
        Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
            Throw New NotImplementedException()
        End Function

    End Class

	Public Class FontWeightConverter
		Implements System.Windows.Data.IValueConverter
        Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
            Dim range = CType(parameter, Point)
            Dim val As Double = CDbl(value)
            Return If(val < range.X, FontWeights.Bold, If(val > range.Y, FontWeights.Bold, FontWeights.Normal))
        End Function
        Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
            Throw New NotImplementedException()
        End Function
	End Class
End Namespace
