MainWindow.xaml.cs 5.1 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
using Microsoft.Win32;
using System.Collections.ObjectModel;

namespace WpfApplication1
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window, INotifyPropertyChanged
    {
        System.Windows.Threading.DispatcherTimer dTimer = new System.Windows.Threading.DispatcherTimer();
        
        private string title2="123";
        /// <summary>
        ///
        /// </summary>
        public virtual string TitleTest
        {
            get { return title2; }
            set
            {
                if (title2 != value)
                {
                    title2 = value;
                    NotifyPropertyChanged("TitleTest");
                }
            }
        }
        
        public Test1 test;
        public MainWindow()
        {
            InitializeComponent();
            test = new Test1();
            
            //this.graphscan1.DataContext = this;
            this.graphscan1.Title = "环形扫描图";
            this.graphscan1.SetBinding(FLY.ControlLibrary.GraphScan.TitleProperty, new Binding("TitleTest"));
            this.DataContext = this;
            this.textBox1.DataContext = test;

            //this.graphscan1.SetBinding(FLY.ControlLibrary.GraphScan.Title2Property, new Binding("TitleTest"));
            //string title2 = this.graphscan1.Title2;

            ObservableCollection<int> datasource = new ObservableCollection<int>();

            // Populate series data
            Random random = new Random();
            int cnt = 160;
            for (int i = 0; i < cnt; i++)
            {
                double angle = 2 * Math.PI * 4 * i / cnt;
                double d = Math.Sin(angle) * 15 + random.Next(5) - 2.5;
                datasource.Add( (int)(d *100) + this.graphscan1.Target);
            }
            for (int i = 20; i < 45; i++)
            {
                datasource[i] = 99999998;
            }
            this.graphscan1.DataSource = datasource;

            stackpanel_graph.DataContext = this.graphscan1;

            this.graphscan1.FirstBoltNo = -cnt/2;
            this.graphscan1.FirstIndex = -1;
            this.graphscan1.LastIndex = cnt;

            this.graphscan1.DataFirst = 2;
            this.graphscan1.DataLast = cnt-2;


            this.graphscan1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline;

            dTimer.Interval = new TimeSpan(0, 0, 1);
            dTimer.Tick += new EventHandler(dTimer_Tick);
            dTimer.Start();
        }
        int test_no = 0;
        void dTimer_Tick(object sender, EventArgs e)
        {
            test_no++;
            TitleTest = test_no.ToString();
            //graphscan1.Title2 = test_no.ToString();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {

        }

        #region INotifyPropertyChanged 成员

        public event PropertyChangedEventHandler PropertyChanged;

        protected void NotifyPropertyChanged(string propertyname)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyname));
            }
        }
        
        #endregion

        int cnt = 0;



        
        private void textBox1_IsMouseCaptureWithinChanged(object sender, DependencyPropertyChangedEventArgs e)
        {

        }

        private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
        {

        }

        private void textBox1_GotFocus(object sender, RoutedEventArgs e)
        {


        }

        private void textBox1_GotMouseCapture(object sender, MouseEventArgs e)
        {

        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            
        }
    }
    public class Test1 : INotifyPropertyChanged 
    {
        private double abc;
        public double ABC 
        {
            get {
                return abc;
            }
            set {
                if (abc != value) 
                {
                    abc = value;
                    NotifyPropertyChanged("ABC");
                }
            }
        }
        #region INotifyPropertyChanged 成员

        public event PropertyChangedEventHandler PropertyChanged;
        protected void NotifyPropertyChanged(string propertyname) 
        {
            if (this.PropertyChanged != null) 
            {
                this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyname));
            }
        }
        #endregion
    }
    public static class FLYUICommands 
    {
        private static RoutedCommand keyboard = new RoutedCommand("Keyboard", typeof(FLYUICommands));
        public static RoutedCommand Keyboard { get { return keyboard; } }
    }
}