im following the binding example in RadControls Silverlight Courseware. ive attached the project..
when the timer is called and the stock quote is updated the gauge control does not reflect the change. any suggestion on what i might be doing wrong would greatly be appreciated
mainpage.xaml
<UserControl x:Class="Silverlightgauge.MainPage"
xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Gauge"
xmlns:abc="clr-namespace:Telerik.Windows;assembly=Telerik.Windows.Controls"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"
Loaded="UserControl_Loaded" >
<UserControl.Resources>
<LinearGradientBrush x:Key="BackgroundBrush">
<GradientStop Color="LightBlue" Offset="0.01" />
<GradientStop Color="SkyBlue" Offset="0.02" />
<GradientStop Color="SlateBlue" Offset="0.8" />
<GradientStop Color="SkyBlue" Offset="0.99" />
<GradientStop Color="LightBlue" Offset="1" />
</LinearGradientBrush>
</UserControl.Resources>
<Grid x:Name="LayoutRoot">
<telerik:RadGauge >
<StackPanel Background="{StaticResource BackgroundBrush}"
HorizontalAlignment="Stretch">
<StackPanel x:Name="spScales" Orientation="Horizontal"
HorizontalAlignment="Center" Margin="10" />
</StackPanel>
</telerik:RadGauge>
</Grid>
</UserControl>
code behind
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Media
Imports System.Windows.Threading
Imports Telerik.Windows.Controls
Imports Telerik.Windows.Controls.Data
Imports Telerik.Windows.Controls.Gauges
Partial Public Class MainPage
Inherits UserControl
Private _random As New Random()
Private _timer As New DispatcherTimer()
Private _stocks As New Stocks()
Public Sub New()
InitializeComponent()
End Sub
Private Sub UserControl_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
' Create a stack panel for each stock and populate
' with text label and linear bar
For Each stock As Stock In _stocks
' initialize a linear scale
Dim scale As New LinearScale()
scale.Min = 0
scale.Max = 100
scale.Width = 70
' add a linear bar, already bound to the stock
scale.Indicators.Add(GetLinearBar(stock))
' create a label to display stock symbol
Dim tb As New TextBlock()
tb.FontWeight = System.Windows.FontWeights.Bold
tb.Text = stock.Symbol
' initialize a stack panel to contain a text label
' and scale. Add the stack panel to the stack panel
' already in the xaml markup
Dim stackPanel As New StackPanel()
stackPanel.VerticalAlignment = VerticalAlignment.Stretch
stackPanel.Children.Add(tb)
stackPanel.Children.Add(scale)
spScales.Children.Add(stackPanel)
Next stock
' initialize and start a timer to update the stocks
AddHandler _timer.Tick, AddressOf _timer_Tick
_timer.Interval = New TimeSpan(0, 0, 0, 1)
_timer.Start()
End Sub
Private Function GetLinearBar(ByVal stock As Stock) As LinearBar
Dim linearBar As New LinearBar()
linearBar.Value = stock.Quote
linearBar.Background = New SolidColorBrush(GetRandomColor())
linearBar.StartWidth = 0.1
linearBar.EndWidth = 0.1
linearBar.RelativeHeight = 0.9
' Bind linear bar to the Quote property of the data object.
Dim binding As New Binding()
binding.Source = stock
binding.Path = New PropertyPath("Quote")
binding.Mode = BindingMode.OneWay
linearBar.SetBinding(linearBar.ValueProperty, binding)
Return linearBar
End Function
Private Function GetRandomColor() As Color
Return Color.FromArgb(150, CByte(_random.Next(0, 255)), _
CByte(_random.Next(0, 255)), CByte(_random.Next(0, 255)))
End Function
Private Sub _timer_Tick(ByVal sender As Object, ByVal e As EventArgs)
For Each stock As Stock In _stocks ' update the symbols
stock.Quote = _random.Next(0, 100)
Next stock
End Sub
End Class
stock.vb
Imports System.ComponentModel
Public Class Stock
Implements INotifyPropertyChanged
Public Event PropertyChanged As PropertyChangedEventHandler
Private _quote As Double
Private _symbol As String
Public Sub New(ByVal symbol As String, ByVal quote As Double)
Me.Quote = quote
Me.Symbol = symbol
End Sub
Public Property Quote() As Double
Get
Return _quote
End Get
Set(ByVal value As Double)
_quote = value
NotifyPropertyChanged("Quote")
End Set
End Property
Public Property Symbol() As String
Get
Return _symbol
End Get
Set(ByVal value As String)
_symbol = value
NotifyPropertyChanged("Symbol")
End Set
End Property
Private Sub NotifyPropertyChanged(ByVal propertyName As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End Sub
Public Event PropertyChanged1(sender As Object, e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
End Class
stocks.vb
Public Class Stocks
Inherits List(Of Stock)
Public Sub New()
Dim symbols As List(Of String) = _
New List(Of String)(New String() {"MSFT", "GOOG", "YHOO", "IBM", "AAPL"})
Dim random As New Random()
For Each symbol As String In symbols
Me.Add(New Stock(symbol, random.Next(0, 100)))
Next symbol
End Sub
End Class
thanks
chris
when the timer is called and the stock quote is updated the gauge control does not reflect the change. any suggestion on what i might be doing wrong would greatly be appreciated
mainpage.xaml
<UserControl x:Class="Silverlightgauge.MainPage"
xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Gauge"
xmlns:abc="clr-namespace:Telerik.Windows;assembly=Telerik.Windows.Controls"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"
Loaded="UserControl_Loaded" >
<UserControl.Resources>
<LinearGradientBrush x:Key="BackgroundBrush">
<GradientStop Color="LightBlue" Offset="0.01" />
<GradientStop Color="SkyBlue" Offset="0.02" />
<GradientStop Color="SlateBlue" Offset="0.8" />
<GradientStop Color="SkyBlue" Offset="0.99" />
<GradientStop Color="LightBlue" Offset="1" />
</LinearGradientBrush>
</UserControl.Resources>
<Grid x:Name="LayoutRoot">
<telerik:RadGauge >
<StackPanel Background="{StaticResource BackgroundBrush}"
HorizontalAlignment="Stretch">
<StackPanel x:Name="spScales" Orientation="Horizontal"
HorizontalAlignment="Center" Margin="10" />
</StackPanel>
</telerik:RadGauge>
</Grid>
</UserControl>
code behind
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Media
Imports System.Windows.Threading
Imports Telerik.Windows.Controls
Imports Telerik.Windows.Controls.Data
Imports Telerik.Windows.Controls.Gauges
Partial Public Class MainPage
Inherits UserControl
Private _random As New Random()
Private _timer As New DispatcherTimer()
Private _stocks As New Stocks()
Public Sub New()
InitializeComponent()
End Sub
Private Sub UserControl_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
' Create a stack panel for each stock and populate
' with text label and linear bar
For Each stock As Stock In _stocks
' initialize a linear scale
Dim scale As New LinearScale()
scale.Min = 0
scale.Max = 100
scale.Width = 70
' add a linear bar, already bound to the stock
scale.Indicators.Add(GetLinearBar(stock))
' create a label to display stock symbol
Dim tb As New TextBlock()
tb.FontWeight = System.Windows.FontWeights.Bold
tb.Text = stock.Symbol
' initialize a stack panel to contain a text label
' and scale. Add the stack panel to the stack panel
' already in the xaml markup
Dim stackPanel As New StackPanel()
stackPanel.VerticalAlignment = VerticalAlignment.Stretch
stackPanel.Children.Add(tb)
stackPanel.Children.Add(scale)
spScales.Children.Add(stackPanel)
Next stock
' initialize and start a timer to update the stocks
AddHandler _timer.Tick, AddressOf _timer_Tick
_timer.Interval = New TimeSpan(0, 0, 0, 1)
_timer.Start()
End Sub
Private Function GetLinearBar(ByVal stock As Stock) As LinearBar
Dim linearBar As New LinearBar()
linearBar.Value = stock.Quote
linearBar.Background = New SolidColorBrush(GetRandomColor())
linearBar.StartWidth = 0.1
linearBar.EndWidth = 0.1
linearBar.RelativeHeight = 0.9
' Bind linear bar to the Quote property of the data object.
Dim binding As New Binding()
binding.Source = stock
binding.Path = New PropertyPath("Quote")
binding.Mode = BindingMode.OneWay
linearBar.SetBinding(linearBar.ValueProperty, binding)
Return linearBar
End Function
Private Function GetRandomColor() As Color
Return Color.FromArgb(150, CByte(_random.Next(0, 255)), _
CByte(_random.Next(0, 255)), CByte(_random.Next(0, 255)))
End Function
Private Sub _timer_Tick(ByVal sender As Object, ByVal e As EventArgs)
For Each stock As Stock In _stocks ' update the symbols
stock.Quote = _random.Next(0, 100)
Next stock
End Sub
End Class
stock.vb
Imports System.ComponentModel
Public Class Stock
Implements INotifyPropertyChanged
Public Event PropertyChanged As PropertyChangedEventHandler
Private _quote As Double
Private _symbol As String
Public Sub New(ByVal symbol As String, ByVal quote As Double)
Me.Quote = quote
Me.Symbol = symbol
End Sub
Public Property Quote() As Double
Get
Return _quote
End Get
Set(ByVal value As Double)
_quote = value
NotifyPropertyChanged("Quote")
End Set
End Property
Public Property Symbol() As String
Get
Return _symbol
End Get
Set(ByVal value As String)
_symbol = value
NotifyPropertyChanged("Symbol")
End Set
End Property
Private Sub NotifyPropertyChanged(ByVal propertyName As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End Sub
Public Event PropertyChanged1(sender As Object, e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
End Class
stocks.vb
Public Class Stocks
Inherits List(Of Stock)
Public Sub New()
Dim symbols As List(Of String) = _
New List(Of String)(New String() {"MSFT", "GOOG", "YHOO", "IBM", "AAPL"})
Dim random As New Random()
For Each symbol As String In symbols
Me.Add(New Stock(symbol, random.Next(0, 100)))
Next symbol
End Sub
End Class
thanks
chris