Thank you.
Yes that definitely helps but now I am getting the attached error when trying to view my MainPage.xaml file in the designer.
Data.vb:
Imports
System.ComponentModel
Public
Class
Data
Implements
INotifyPropertyChanged
Public
Event
PropertyChanged
As
PropertyChangedEventHandler
Implements
INotifyPropertyChanged.PropertyChanged
Private
_serviceCategory
As
String
Private
_costIndex
As
Double
Public
Sub
New
(
ByVal
serviceCategory
As
String
,
ByVal
costIndex
As
Double
)
Me
._serviceCategory = serviceCategory
Me
._costIndex = costIndex
End
Sub
Public
Property
ServiceCategory()
As
String
Get
Return
Me
._serviceCategory
End
Get
Set
(
ByVal
value
As
String
)
If
String
.Compare(
Me
._serviceCategory, Value, StringComparison.CurrentCultureIgnoreCase) = 0
Then
Return
End
If
Me
._serviceCategory = Value
End
Set
End
Property
Public
Property
CostIndex()
As
Double
Get
Return
Me
._costIndex
End
Get
Set
(
ByVal
value
As
Double
)
If
Me
._costIndex = Value
Then
Return
End
If
Me
._costIndex = Value
End
Set
End
Property
Protected
Overridable
Sub
OnPropertyChanged(propertyName
As
String
)
RaiseEvent
PropertyChanged(
Me
,
New
PropertyChangedEventArgs(propertyName))
End
Sub
End
Class
DataViewModel.vb
Imports
System.ComponentModel
Imports
System.Windows.Media
Public
Class
DataViewModel
Implements
INotifyPropertyChanged
Public
Event
PropertyChanged
As
PropertyChangedEventHandler
Implements
INotifyPropertyChanged.PropertyChanged
Private
_data
As
Data
Private
_populationColor
As
Brush
Public
Sub
New
(data
As
Data)
Me
._data = data
AddHandler
data.PropertyChanged,
AddressOf
HandleDataPropertyChanged
Me
.UpdatePopulationColor()
End
Sub
Public
ReadOnly
Property
Data()
As
Data
Get
Return
_data
End
Get
End
Property
Public
Property
PopulationColor()
As
Brush
Get
Return
_populationColor
End
Get
Private
Set
If
Object
.Equals(
Me
._populationColor, value)
Then
Return
End
If
Me
._populationColor = value
Me
.OnPropertyChanged(
"PopulationColor"
)
End
Set
End
Property
Private
Sub
HandleDataPropertyChanged(sender
As
Object
, e
As
PropertyChangedEventArgs)
If
e.PropertyName =
"Population"
Then
Me
.UpdatePopulationColor()
End
If
End
Sub
Protected
Overridable
Sub
OnPropertyChanged(propertyName
As
String
)
RaiseEvent
PropertyChanged(
Me
,
New
PropertyChangedEventArgs(propertyName))
End
Sub
Private
Function
CreateBrush(color
As
String
)
As
Brush
Return
New
SolidColorBrush(
Me
.GetColorFromHexString(color))
End
Function
Private
Function
GetColorFromHexString(s
As
String
)
As
Color
s = s.Replace(
"#"
,
String
.Empty)
Dim
a
As
Byte
= System.Convert.ToByte(s.Substring(0, 2), 16)
Dim
r
As
Byte
= System.Convert.ToByte(s.Substring(2, 2), 16)
Dim
g
As
Byte
= System.Convert.ToByte(s.Substring(4, 2), 16)
Dim
b
As
Byte
= System.Convert.ToByte(s.Substring(6, 2), 16)
Return
Color.FromArgb(a, r, g, b)
End
Function
Private
Sub
UpdatePopulationColor()
If
Me
.Data.CostIndex < 1
Then
Me
.PopulationColor =
Me
.CreateBrush(
"#00CD00"
)
Else
Me
.PopulationColor =
Me
.CreateBrush(
"#EE0000"
)
End
If
End
Sub
End
Class
ExampleViewModel.vb
#Region "Imports"
Imports
System.ComponentModel
#End Region
Public
Class
ExampleViewModel
Implements
INotifyPropertyChanged
#Region "Public Events"
Public
Event
PropertyChanged
As
PropertyChangedEventHandler
Implements
INotifyPropertyChanged.PropertyChanged
#End Region
Private
_costIndexData
As
List(Of DataViewModel)
#Region "Public Properties"
Public
Property
TinNumber
As
String
Public
Property
SubTinSequenceNumber
As
String
#End Region
Public
Sub
New
()
BeginRequest()
End
Sub
Public
Property
CostIndexData
As
List(OF DataViewModel)
Get
Return
_costIndexData
End
Get
Set
(
ByVal
value
As
List(Of DataViewModel))
_costIndexData = value
' Call NotifyPropertyChanged when the property is updated
NotifyPropertyChanged(
"CostIndexData"
)
End
Set
End
Property
Private
Sub
BeginRequest()
Dim
lProviderService
As
New
ProviderService.ProviderDashboardServiceClient()
AddHandler
lProviderService.GetCostIndexSummaryDataCompleted,
AddressOf
CostIndexSummaryDataCompletedCallback
lProviderService.GetCostIndexSummaryDataAsync(TinNumber, SubTinSequenceNumber)
End
Sub
Private
Sub
NotifyPropertyChanged(
ByVal
info
As
String
)
RaiseEvent
PropertyChanged(
Me
,
New
PropertyChangedEventArgs(info))
End
Sub
Private
Sub
CostIndexSummaryDataCompletedCallback(
ByVal
sender
As
Object
,
ByVal
e
As
ProviderService.GetCostIndexSummaryDataCompletedEventArgs)
Dim
lRecords
As
List(Of Dictionary(Of
String
,
String
)) = e.Result
Dim
lDatalist
As
New
List(Of Data)
For
Each
lRecord
As
Dictionary(Of
String
,
String
)
In
lRecords
lDatalist.Add(
New
Data(lRecord(
"ServiceCategory"
).ToString.Trim, lRecord(
"CostIndex"
)))
Next
Dim
lModelList
As
New
List(Of DataViewModel)
For
Each
lDataItem
As
Data
In
lDatalist
lModelList.Add(
New
DataViewModel(lDataItem))
Next
CostIndexData = lModelList
End
Sub
End
Class
MainPage.xaml
<
UserControl
x:Class
=
"Ebms.Silverlight.Controls.MainPage"
mc:Ignorable
=
"d"
d:DesignWidth
=
"640"
d:DesignHeight
=
"480"
xmlns:Example
=
"clr-namespace:MyCompany.Silverlight.Controls"
>
<
UserControl.DataContext
>
<
Example:ExampleViewModel
/>
</
UserControl.DataContext
>
<
UserControl.Resources
>
<
Style
x:Key
=
"CustomStyle"
TargetType
=
"telerik:Bar"
>
<
Setter
Property
=
"Template"
>
<
Setter.Value
>
<
ControlTemplate
TargetType
=
"telerik:Bar"
>
<
Canvas
>
<
Rectangle
x:Name
=
"PART_DefiningGeometry"
Height
=
"{TemplateBinding ItemActualHeight}"
Width
=
"{TemplateBinding ItemActualWidth}"
Fill
=
"{Binding DataItem.PopulationColor}"
/>
<
Canvas.RenderTransform
>
<
ScaleTransform
x:Name
=
"PART_AnimationTransform"
ScaleY
=
"0"
/>
</
Canvas.RenderTransform
>
</
Canvas
>
</
ControlTemplate
>
</
Setter.Value
>
</
Setter
>
</
Style
>
<
Style
x:Key
=
"CustomLabelStyle"
TargetType
=
"telerik:SeriesItemLabel"
>
<
Setter
Property
=
"HorizontalContentAlignment"
Value
=
"Center"
/>
<
Setter
Property
=
"Padding"
Value
=
"2,0"
/>
<
Setter
Property
=
"IsHitTestVisible"
Value
=
"False"
/>
<
Setter
Property
=
"Template"
>
<
Setter.Value
>
<
ControlTemplate
TargetType
=
"telerik:SeriesItemLabel"
>
<
Canvas
x:Name
=
"PART_MainContainer"
>
<
Path
Visibility
=
"{TemplateBinding ConnectorVisibility}"
Style
=
"{TemplateBinding ConnectorStyle}"
Stroke
=
"{TemplateBinding Stroke}"
StrokeThickness
=
"{TemplateBinding StrokeThickness}"
>
<
Path.Data
>
<
PathGeometry
>
<
PathGeometry.Figures
>
<
PathFigure
x:Name
=
"PART_Connector"
>
<
PathFigure.Segments
>
<
PolyLineSegment
/>
</
PathFigure.Segments
>
</
PathFigure
>
</
PathGeometry.Figures
>
</
PathGeometry
>
</
Path.Data
>
</
Path
>
<
Border
x:Name
=
"PART_TextContainer"
Style
=
"{TemplateBinding LabelStyle}"
BorderBrush
=
"Transparent"
Background
=
"Transparent"
>
<
TextBlock
Foreground
=
"Black"
TextAlignment
=
"{TemplateBinding HorizontalContentAlignment}"
Margin
=
"0"
Text
=
"{TemplateBinding Content}"
/>
</
Border
>
</
Canvas
>
</
ControlTemplate
>
</
Setter.Value
>
</
Setter
>
</
Style
>
</
UserControl.Resources
>
<
Grid
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"*"
/>
<
RowDefinition
Height
=
"Auto"
/>
</
Grid.RowDefinitions
>
<
telerik:RadChart
x:Name
=
"RadChart1"
ItemsSource
=
"{Binding CostIndexData}"
>
<
telerik:RadChart.SeriesMappings
>
<
telerik:SeriesMapping
>
<
telerik:SeriesMapping.SeriesDefinition
>
<
telerik:BarSeriesDefinition
ItemStyle
=
"{StaticResource CustomStyle}"
SeriesItemLabelStyle
=
"{StaticResource CustomLabelStyle}"
ItemLabelFormat
=
"#Y{0.}"
>
<
telerik:BarSeriesDefinition.LabelSettings
>
<
telerik:BarLabelSettings
LabelDisplayMode
=
"MidPoint"
Distance
=
"0"
/>
</
telerik:BarSeriesDefinition.LabelSettings
>
</
telerik:BarSeriesDefinition
>
</
telerik:SeriesMapping.SeriesDefinition
>
<
telerik:ItemMapping
FieldName
=
"Data.CostIndex"
DataPointMember
=
"YValue"
/>
<
telerik:ItemMapping
FieldName
=
"Data.ServiceCategory"
DataPointMember
=
"XCategory"
/>
</
telerik:SeriesMapping
>
</
telerik:RadChart.SeriesMappings
>
<
telerik:RadChart.DefaultView
>
<
telerik:ChartDefaultView
ChartLegendPosition
=
"Bottom"
>
<
telerik:ChartDefaultView.ChartTitle
>
<
telerik:ChartTitle
Content
=
"Population change (average annual change, thousand)"
/>
</
telerik:ChartDefaultView.ChartTitle
>
<
telerik:ChartDefaultView.ChartArea
>
<
telerik:ChartArea
>
<
telerik:ChartArea.AxisX
>
<
telerik:AxisX
MajorTicksVisibility
=
"Collapsed"
/>
</
telerik:ChartArea.AxisX
>
<
telerik:ChartArea.AxisY
>
<
telerik:AxisY
AutoRange
=
"False"
MinValue
=
"-7000"
MaxValue
=
"7000"
Step
=
"1000"
MinorTicksVisibility
=
"Collapsed"
MajorTicksVisibility
=
"Collapsed"
/>
</
telerik:ChartArea.AxisY
>
</
telerik:ChartArea
>
</
telerik:ChartDefaultView.ChartArea
>
</
telerik:ChartDefaultView
>
</
telerik:RadChart.DefaultView
>
</
telerik:RadChart
>
</
Grid
>
</
UserControl
>
The error is pointing to the line:
Dim
lRecords As List(Of Dictionary(Of String, String
)) = e.Result
In the CostIndexSummaryDataCompletedCallback method of the ExampleViewModel class.
I know I must be doing something wrong but I can't tell what. Help!!
Thanks!