Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ===== MainPage.xaml =====
- <UserControl x:Class="SilverlightApplication3.MainPage"
- 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"
- xmlns:oxy="clr-namespace:OxyPlot.Silverlight;assembly=OxyPlot.Silverlight"
- mc:Ignorable="d"
- d:DesignHeight="300" d:DesignWidth="400">
- <Grid x:Name="LayoutRoot" Background="White">
- <oxy:Plot x:Name="FFTplotter"/>
- </Grid>
- </UserControl>
- ===== MainPage.xaml.cs =====
- using System;
- using OxyPlot;
- using System.Collections.ObjectModel;
- using System.Collections.Specialized;
- using System.ComponentModel;
- using System.Windows.Controls;
- using System.Collections.Generic;
- namespace SilverlightApplication3
- {
- public partial class MainPage : UserControl, INotifyPropertyChanged
- {
- public MainPage()
- {
- InitializeComponent();
- FFTplotter.Model = new PlotModel();
- SetPlotData();
- SelectedValues = new ObservableCollection<int>();
- FFTplotter.Model.MouseDown += MouseDown;
- FFTplotter.Model.MouseUp += MouseUp;
- FFTplotter.Model.MouseMove += MouseMoved;
- }
- private void SetPlotData()
- {
- // Set the type of lineseries and the kind of visualization
- var ls = new LineSeries();
- var ps = new List<DataPoint>();
- Random random = new Random();
- var min = 0;
- var max = 100;
- for (int x = 0; x < 1000; x++)
- {
- var dataPoint = 1;
- ps.Add(new DataPoint(x, random.Next(min, max)));
- }
- ls.ItemsSource = ps;
- FFTplotter.Model.Series.Clear();
- FFTplotter.Model.Series.Add(ls);
- FFTplotter.Model.InvalidatePlot(true);
- }
- private ObservableCollection<int> _selectedFrequencies;
- public ObservableCollection<int> SelectedValues
- {
- get { return _selectedFrequencies; }
- set
- {
- if (value == null) return;
- _selectedFrequencies = value;
- NotifyPropertyChanged("SelectedFrequencies");
- }
- }
- private bool _mousedown;
- private void MouseDown(object sender, OxyMouseEventArgs e)
- {
- _mousedown = true;
- e.Handled = true;
- }
- private void MouseUp(object sender, OxyMouseEventArgs e)
- {
- _mousedown = false;
- RenderSelectedValue(e);
- e.Handled = true;
- }
- private void MouseMoved(object sender, OxyMouseEventArgs e)
- {
- if (_mousedown)
- {
- RenderSelectedValue(e);
- e.Handled = true;
- }
- }
- private ObservableCollection<Annotation> _selectedFrequencylines;
- private static bool RenderingLines;
- private void RenderSelectedValue(OxyMouseEventArgs e)
- {
- if (!RenderingLines)
- {
- RenderingLines = true;
- Axis xaxis, yaxis;
- FFTplotter.Model.GetAxesFromPoint(e.Position, out xaxis, out yaxis);
- if (xaxis == null) return;
- double x = xaxis.InverseTransform(e.Position.X);
- var a = new LineAnnotation
- {
- Type = LineAnnotationType.Vertical,
- X = x,
- Color = OxyColors.Gray,
- LineStyle = LineStyle.Solid,
- };
- // Add the new line
- FFTplotter.Model.Annotations.Add(a);
- FFTplotter.Model.Title = FFTplotter.Model.Annotations.Count + " annotations added";
- FFTplotter.Model.InvalidatePlot(false);
- RenderingLines = false;
- }
- else
- {
- }
- }
- #region INotifyPropertyChanged Members
- public event PropertyChangedEventHandler PropertyChanged;
- /// <summary>
- /// Generic NotifyPropertyChanged function
- /// </summary>
- /// <param name="propertyname"> Name of the property that has changed </param>
- private void NotifyPropertyChanged(string propertyname)
- {
- if (PropertyChanged != null)
- {
- PropertyChanged(this, new PropertyChangedEventArgs(propertyname));
- }
- }
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement