コード例 #1
0
        /// <summary>
        ///  Action for the File->Paste command.
        /// </summary>
        ///
        public void Paste_Executed(object target)
        {
            var text = Clipboard.GetText();

            var reader = new CsvReader(new StringReader(text), false, '\t');
            var lines = reader.ReadToEnd();

            lines.Reverse();

            int startIndex = Values.IndexOf(CurrentCell.Item as SampleViewModel);
            if (startIndex == -1)
                startIndex = Values.Count;

            foreach (var line in lines)
            {
                var sample = new SampleViewModel();

                double value;
                if (!Double.TryParse(line[0], out value))
                    continue;

                sample.Value = value;

                if (line.Length > 1)
                {
                    double weight = 1;
                    if (Double.TryParse(line[1], out weight))
                        sample.Weight = weight;
                }

                Values.Insert(startIndex, sample);
            }
        }