This is a migrated thread and some comments may be shown as answers.

Updating LinearBar Value

1 Answer 53 Views
Gauge
This is a migrated thread and some comments may be shown as answers.
Abraham
Top achievements
Rank 1
Abraham asked on 21 Dec 2010, 06:32 PM
Hello,

I have used your thermometer example and now want to bind the value of the LinearBar to the latest value in a SQL Table. I'm using a service and have been successful in binding the data initially, however when a new value is inserted into the SQL Table, I cannot figure out how to have the LinearBar value update. Is this possible? Thank you

-Abraham

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 23 Dec 2010, 05:46 PM
Hello Abraham,

When you use a service to get the latest value from a SQL Table there is no event raised when a new record is inserted.
I think you can use a timer which will refresh the value from a service.
The sample code below requests the service to get the Temperature property asynchronously. It uses the DispatcherTimer instance to refresh a data in 3 seconds after each request complete.
using System;
using System.ComponentModel;
using System.Windows.Controls;
using System.Windows.Threading;
using SQLServerTemperature.ServiceReference1;
  
namespace SQLServerTemperature
{
    public partial class MainPage : UserControl, INotifyPropertyChanged
    {
        // WCF service client instance
        private Service1Client client = new Service1Client();
  
        private DispatcherTimer timer;
  
        // refresh interval to request WCF service
        private TimeSpan refreshInterval = TimeSpan.FromSeconds(3);
  
        private double temperature;
  
        // bound property
        public double Temperature
        {
            get
            {
                return this.temperature;
            }
            set
            {
                this.temperature = value;
                OnPropertyChanged("Temperature");
            }
        }
  
        public MainPage()
        {
            InitializeComponent();
  
            this.LayoutRoot.DataContext = this;
  
            // timer initialization
            this.timer = new DispatcherTimer();
            this.timer.Interval = this.refreshInterval;
            this.timer.Tick += new EventHandler(timer_Tick);
  
            // assign request completed handler
            this.client.GetTemperatureCompleted += new EventHandler<GetTemperatureCompletedEventArgs>(client_GetTemperatureCompleted);
            // initial request
            this.client.GetTemperatureAsync();
        }
  
        void timer_Tick(object sender, EventArgs e)
        {
            this.timer.Stop();
  
            // request to the WCF service to update value
            this.client.GetTemperatureAsync();
        }
  
        void client_GetTemperatureCompleted(object sender, GetTemperatureCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                // update value
                this.Temperature = e.Result;
            }
  
            // start timer to refresh the value
            this.timer.Start();
        }
  
        public event PropertyChangedEventHandler PropertyChanged;
  
        protected void OnPropertyChanged(string name)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(name));
            }
        }
    }
}

Kind regards,
Andrey Murzov
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
Gauge
Asked by
Abraham
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or