Monday, December 10, 2012

How can i run a query and pull information (x and y values) from the results of that query in Silverlight?

How can i run a query and pull information (x and y values) from the results of that query in Silverlight?

I have a silverlight application that simply plots points on a graph. The points that it plots come from a sql query.

The silverlight program will have to run the query and pull the relevant data on its own.

How do i achieve this kind of functionality??

thanks!

Answers & Comments...

Answer: 1

You don't say how many times it needs to plot the data per sec/min? Is it just to plot once. If so then when your app first loads write an asynchronous call and have the call query sql and return the results in the callback..

If the program needs to return data at set intervals then you'll need a dispatcher timer or something similar..

Ok something like this..

public class MyClass : INotifyPropertyChanged {     public MyClass()     {         DispatcherTimer timer = new DispatcherTimer();         timer.Tick += OnTimerTick;         timer.Interval = TimeSpan.FromSeconds(300);     }  private void OnTimerTick(object sender, EventArgs e)     {         var result = await UpdateGraphPoints();         MyGraphPoints = this.PopulateTheGraph(result);     }      private async Task<List<MyGraphPoint>> UpdateGraphPoints()     {         var oper = await YourDatabaseQueryMethod();         return oper;     }      private ObservableCollection<MyGraphPoint> PopulateTheGraph(object result)     {      }      private ObservableCollection<MyGraphPoint> myGraphPoints;      public ObservableCollection<MyGraphPoint> MyGraphPoints     {         get { return this.myGraphPoints; }         set         {             myGraphPoints = value;             OnPropertyChanged("MyGraphPoints");         }     }  private void OnPropertyChanged(string propertyName)     {         if (PropertyChanged != null)         {             PropertyChanged(this, new PropertyChangedEventArgs(propertyName));         }     } 

}

public class MyGraphPoint : INotifyPropertyChanged {     public event PropertyChangedEventHandler PropertyChanged;      private int xValue;      public int XValue     {         get { return xValue; }         set         {             this.xValue = value;             this.OnPropertyChanged("XValue");         }     }      private int yValue;      public int YValue     {         get { return yValue; }         set         {             this.yValue = value;             this.OnPropertyChanged("YValue");         }     }      private void OnPropertyChanged(string propertyName)     {         if (PropertyChanged != null)         {             PropertyChanged(this, new PropertyChangedEventArgs(propertyName));         }     } } 

And then in your xaml - bind the MyGraphPoints observable collection to your graph control.

by : The Unculled Badgerhttp://stackoverflow.com/users/1272589




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog