KeyValuePair <double,double>和这些</double,double>的列表

时间:2014-05-14 23:54:52

标签: c# charts

我必须在其中显示包含4个系列的图表。我能够使用我的数据来完成这项工作。 但是,当我开始更新数据列表时,它会给出一个解析错误(见下文)。 I.E它甚至在尝试“更新”图表之前给了我一个错误。哎呀,我甚至从等式中删除了图表,我仍然得到相同的解析错误。

以下是我的名单的宣布方式:

public partial class MainWindow : Window
    {
List<KeyValuePair<double, double>> channel1List = new List<KeyValuePair<double, double>>();
        List<KeyValuePair<double, double>> channel2List = new List<KeyValuePair<double, double>>();
        List<KeyValuePair<double, double>> channel3List = new List<KeyValuePair<double, double>>();
        List<KeyValuePair<double, double>> channel4List = new List<KeyValuePair<double, double>>();
        List<List<KeyValuePair<double, double>>> rampsList = new List<List<KeyValuePair<double, double>>>();

在我的主要内容中,我得到了:

 // DEFAULT CHANNEL 1 LIST
            channel1List.Add(new KeyValuePair<double, double>(0, 0));
            channel1List.Add(new KeyValuePair<double, double>(DMIN1, 0));
            channel1List.Add(new KeyValuePair<double, double>(DMAX1, 100));
            channel1List.Add(new KeyValuePair<double, double>(30, 100));
            // DEFAULT CHANNEL 2 LIST
            channel2List.Add(new KeyValuePair<double, double>(0, 0));
            channel2List.Add(new KeyValuePair<double, double>(DMIN2, 0));
            channel2List.Add(new KeyValuePair<double, double>(DMAX2, 100));
            channel2List.Add(new KeyValuePair<double, double>(30, 100));
            // DEFAULT CHANNEL 3 LIST
            channel3List.Add(new KeyValuePair<double, double>(0, 0));
            channel3List.Add(new KeyValuePair<double, double>(DMIN3, 0));
            channel3List.Add(new KeyValuePair<double, double>(DMAX3, 100));
            channel3List.Add(new KeyValuePair<double, double>(30, 100));
            // DEFAULT CHANNEL 4 LIST
            channel4List.Add(new KeyValuePair<double, double>(0, 0));
            channel4List.Add(new KeyValuePair<double, double>(DMIN4, 0));
            channel4List.Add(new KeyValuePair<double, double>(DMAX4, 100));
            channel4List.Add(new KeyValuePair<double, double>(30, 100));


            channel1List.RemoveAt(1);
            channel1List.Insert(1, new KeyValuePair<double, double>(DMIN1, 0));


            // DEFAULT LIST OF RAMPS
            rampsList.Add(channel1List);
            rampsList.Add(channel2List);
            rampsList.Add(channel3List);
            rampsList.Add(channel4List);
            // DRAW DEFAULT CHART
            rampsChart.DataContext = rampsList;

注意到2行“channel1.RemoveAt(1)...... / ...” 这些只是为了测试,我能够删除一个条目并用一个新的替换它。 这些系列每个只有4个点,我总是只需要更新第1项和第2项.0和3永远不会更新。

无论如何,上面的代码工作正常。它绘制了图表。没有解析错误。

现在,就像我说的那样,当用户移动滑块时我需要更新此图表。我为这个滑块设置了一个ValueChanged事件,可以很好地更新几个标签。

但如果我有相同的2行:

channel1List.RemoveAt(1);
channel1List.Insert(1, new KeyValuePair<double, double>(DMIN1, 0));

然后它在构建项目时没有给我任何错误,但是当我点击Start ...时给了我这个错误

PresentationFramework.dll中出现未处理的“System.Windows.Markup.XamlParseException”类型异常

我不知道为什么会这样做。

任何想法? 谢谢 史蒂夫

编辑:完整堆栈:

'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\12.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\12.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\12.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'Z:\Temperature Controller\Software\C#\SWFT Imperium (WPF)\SWFT Imperium\SWFT Imperium\bin\Debug\SWFT Imperium.vshost.exe'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xaml\v4.0_4.0.0.0__b77a5c561934e089\System.Xaml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\WindowsBase\v4.0_4.0.0.0__31bf3856ad364e35\WindowsBase.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\PresentationCore\v4.0_4.0.0.0__31bf3856ad364e35\PresentationCore.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework\v4.0_4.0.0.0__31bf3856ad364e35\PresentationFramework.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The thread 0x2d84 has exited with code 259 (0x103).
The thread 0x2ae0 has exited with code 259 (0x103).
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'Z:\Temperature Controller\Software\C#\SWFT Imperium (WPF)\SWFT Imperium\SWFT Imperium\bin\Debug\SWFT Imperium.exe'. Symbols loaded.
Step into: Stepping over non-user code 'SWFT_Imperium.App..ctor'
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Step into: Stepping over non-user code 'SWFT_Imperium.App.Main'
Step into: Stepping over non-user code 'SWFT_Imperium.App.InitializeComponent'
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'Z:\Temperature Controller\Software\C#\SWFT Imperium (WPF)\SWFT Imperium\SWFT Imperium\bin\Debug\System.Windows.Controls.DataVisualization.Toolkit.dll'. Symbols loaded.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework.Aero\v4.0_4.0.0.0__31bf3856ad364e35\PresentationFramework.Aero.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationUI\v4.0_4.0.0.0__31bf3856ad364e35\PresentationUI.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework-SystemXml\v4.0_4.0.0.0__b77a5c561934e089\PresentationFramework-SystemXml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SWFT Imperium.vshost.exe' (CLR v4.0.30319: SWFT Imperium.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\UIAutomationTypes\v4.0_4.0.0.0__31bf3856ad364e35\UIAutomationTypes.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
An unhandled exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll
Additional information: 'The invocation of the constructor on type 'SWFT_Imperium.MainWindow' that matches the specified binding constraints threw an exception.' Line number '4' and line position '9'.

程序'[4628] SWFT Imperium.vshost.exe已退出,代码为0(0x0)。

edit2:XAML的前几行:

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" x:Class="Swiftech_Imperium.MainWindow"
        Title="SWFT Imperium" Height="435" Width="510" ResizeMode="CanMinimize" WindowStartupLocation="CenterScreen" Icon="Swiftech.ico" Closing="Window_Closing" MouseDown="Grid_MouseDown" WindowStyle="None" BorderThickness="1" BorderBrush="Black" Foreground="Black">
    <Window.Resources>

1 个答案:

答案 0 :(得分:0)

我怀疑你的

  

channel1List.RemoveAt(1);

代码在您的

之前执行
  

channel1List.Add(new KeyValuePair<double, double>(0, 0)); channel1List.Add(new KeyValuePair<double, double>(DMIN1, 0)); channel1List.Add(new KeyValuePair<double, double>(DMAX1, 100)); channel1List.Add(new KeyValuePair<double, double>(30, 100));

导致此异常

确保执行顺序始终正确,例如通过从构造函数调用collection fill方法。