Hi,
Yesterdaty I was at a lecture on Architecture Patterns for Silverlight held by Deyan Varchev from Telerik. There I asked a question of a problem I have with a Needle control inside a Gauge and I was asked to supply the example solution, so here it is.
Page.xaml:
Page.xaml.cs:
And here is the DummyClass definition:
When you start the application and start pressing the Button to generate different random values for the DoubleValue Property of the DummyClass, the Text Property of the TextBox is changed as expected, but the Needle of the Gauge stays on "0" at all times. Am I doing something wrong ?
Yesterdaty I was at a lecture on Architecture Patterns for Silverlight held by Deyan Varchev from Telerik. There I asked a question of a problem I have with a Needle control inside a Gauge and I was asked to supply the example solution, so here it is.
Page.xaml:
<UserControl x:Class="GaugeTest.Page" |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
Width="400" Height="336" xmlns:Telerik_Windows_Controls_Gauges="clr-namespace:Telerik.Windows.Controls.Gauges;assembly=Telerik.Windows.Controls.Charting"> |
<Grid x:Name="LayoutRoot" Background="White"> |
<Telerik_Windows_Controls_Gauges:RadialGauge Height="250" Margin="75,8,75,78" Width="250"> |
<Telerik_Windows_Controls_Gauges:RadialScale Height="Auto" Width="Auto" Min="0" Max="400"> |
<Telerik_Windows_Controls_Gauges:RadialScale.Indicators> |
<Telerik_Windows_Controls_Gauges:Needle Value="{Binding Path=DoubleValue, Mode=OneWay}"/> |
</Telerik_Windows_Controls_Gauges:RadialScale.Indicators> |
</Telerik_Windows_Controls_Gauges:RadialScale> |
</Telerik_Windows_Controls_Gauges:RadialGauge> |
<StackPanel Height="Auto" Margin="8,0,8,8" VerticalAlignment="Bottom" Orientation="Horizontal" HorizontalAlignment="Center"> |
<Button Height="27" Content="Set new random value" Click="Button_Click" Margin="0,0,10,0"/> |
<TextBlock Height="Auto" Width="Auto" Text="New Value:" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,10,0"/> |
<TextBox Height="Auto" Width="150" Text="{Binding Path=DoubleValue, Mode=TwoWay}" TextWrapping="Wrap" VerticalAlignment="Center" Margin="0,2,0,2"/> |
</StackPanel> |
</Grid> |
</UserControl> |
Page.xaml.cs:
using System; |
using System.Collections.Generic; |
using System.Linq; |
using System.Net; |
using System.Windows; |
using System.Windows.Controls; |
using System.Windows.Documents; |
using System.Windows.Input; |
using System.Windows.Media; |
using System.Windows.Media.Animation; |
using System.Windows.Shapes; |
namespace GaugeTest |
{ |
public partial class Page : UserControl |
{ |
private DummyClass dc; |
private Random rnd; |
public Page() |
{ |
InitializeComponent(); |
dc = new DummyClass(); |
LayoutRoot.DataContext = dc; |
rnd = new Random(); |
dc.GenerateNewNumber(rnd); |
} |
private void Button_Click(object sender, RoutedEventArgs e) |
{ |
dc.GenerateNewNumber(rnd); |
} |
} |
} |
And here is the DummyClass definition:
using System; |
using System.Net; |
using System.Windows; |
using System.Windows.Controls; |
using System.Windows.Documents; |
using System.Windows.Ink; |
using System.Windows.Input; |
using System.Windows.Media; |
using System.Windows.Media.Animation; |
using System.Windows.Shapes; |
using System.ComponentModel; |
namespace GaugeTest |
{ |
public class DummyClass : INotifyPropertyChanged |
{ |
#region INotifyPropertyChanged Members |
public event PropertyChangedEventHandler PropertyChanged; |
#endregion |
private double m_DoubleValue; |
public DummyClass() |
{ |
DoubleValue = 0; |
} |
public double DoubleValue |
{ |
get |
{ |
return m_DoubleValue; |
} |
set |
{ |
m_DoubleValue = value; |
NotifyPropertyChanged("DoubleValue"); |
} |
} |
public void GenerateNewNumber(Random rnd) |
{ |
int newValue = rnd.Next(0, 400); |
DoubleValue = (double)newValue; |
} |
private void NotifyPropertyChanged(string propertyName) |
{ |
if (PropertyChanged != null) |
{ |
PropertyChanged(this, |
new PropertyChangedEventArgs(propertyName)); |
} |
} |
} |
} |
When you start the application and start pressing the Button to generate different random values for the DoubleValue Property of the DummyClass, the Text Property of the TextBox is changed as expected, but the Needle of the Gauge stays on "0" at all times. Am I doing something wrong ?