Wpf 为TabControl中的图表使用数据模板时出错
我使用C#,wpf,WPFToolkit。我创建TabControl。这些选项卡包含图表和其他信息。我使用模板和选择器 xaml: 视图模型:Wpf 为TabControl中的图表使用数据模板时出错,wpf,charts,datatemplate,tabcontrol,wpftoolkit,Wpf,Charts,Datatemplate,Tabcontrol,Wpftoolkit,我使用C#,wpf,WPFToolkit。我创建TabControl。这些选项卡包含图表和其他信息。我使用模板和选择器 xaml: 视图模型: List<TabViewModel> tabList = new List<TabViewModel>(); tabList.Add(new TabViewModel(IsChart=true)); tabList.Add(new TabViewModel(IsChart=false)); .... TabList = new L
List<TabViewModel> tabList = new List<TabViewModel>();
tabList.Add(new TabViewModel(IsChart=true));
tabList.Add(new TabViewModel(IsChart=false));
....
TabList = new ListCollectionView(tabList);
List tabList=new List();
tabList.Add(新TabViewModel(IsChart=true));
tabList.Add(新TabViewModel(IsChart=false));
....
TabList=新列表集合视图(TabList);
项目运行时没有错误。该图构建正确。但是如果切换选项卡,您将收到一个错误:
Exception Type: System.InvalidOperationException
Exception: Cannot determine the size of an axis without an orientation.
Additional information:
System.Object:
Stack Trace:
at
System.Windows.Controls.DataVisualization.Charting.DisplayAxis.GetLength(Size availableSize)
at System.Windows.Controls.DataVisualization.Charting.DisplayAxis.get_ActualLength()
at
System.Windows.Controls.DataVisualization.Charting.RangeAxis.UpdateActualRange()
at System.Windows.Controls.DataVisualization.Charting.RangeAxis.System.Windows.Controls.DataVisualization.Charting.IRangeConsumer.RangeChanged(IRangeProvider usesRangeAxis, Range`1 range)
at System.Windows.Controls.DataVisualization.Charting.DataPointSeriesWithAxes.UpdateActualIndependentAxis()
at System.Windows.Controls.DataVisualization.Charting.DataPointSeriesWithAxes.<>c__DisplayClass33.<OnDataPointsChanged>b__31()
at System.Windows.Controls.DataVisualization.Charting.DataPointSeries.<>c__DisplayClass1c.<InvokeOnLayoutUpdated>b__1b(Object , EventArgs )
at System.Windows.ContextLayoutManager.fireLayoutUpdateEvent()
at System.Windows.ContextLayoutManager.UpdateLayout()
at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.Resize(ICompositionTarget resizedCompositionTarget)
at System.Windows.Interop.HwndTarget.OnResize()
at System.Windows.Interop.HwndTarget.HandleMessage(WindowMessage msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
异常类型:System.InvalidOperationException
异常:无法确定没有方向的轴的大小。
其他信息:
系统对象:
堆栈跟踪:
在
System.Windows.Controls.DataVisualization.Charting.DisplayAxis.GetLength(可用大小大小)
在System.Windows.Controls.DataVisualization.Charting.DisplayAxis.get_ActualLength()中
在
System.Windows.Controls.DataVisualization.Charting.RangeAxis.UpdateActualRange()
位于System.Windows.Controls.DataVisualization.Charting.RangeAxis.System.Windows.Controls.DataVisualization.Charting.IRangeConsumer.RangeChanged(IRangeProvider使用RangeAxis,范围`1范围)
在System.Windows.Controls.DataVisualization.Charting.DataPointSeriesWithAxes.UpdateActualEndEndantaxis()中
在System.Windows.Controls.DataVisualization.Charting.DataPointSeriesWithAxes.c__DisplayClass33.b__31()中
在System.Windows.Controls.DataVisualization.Charting.DataPointSeries.c__DisplayClass1c.b__1b(对象,事件参数)
位于System.Windows.ContextLayoutManager.fireLayoutUpdateEvent()处
位于System.Windows.ContextLayoutManager.UpdateLayout()处
位于System.Windows.ContextLayoutManager.UpdateLayoutCallback(对象参数)
位于System.Windows.Media.MediaContext.InvokeRenderCallback.DoWork()处
在System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()中
位于System.Windows.Media.MediaContext.RenderMessageHandlerCore(对象大小调整的CompositionTarget)
位于System.Windows.Media.MediaContext.RenderMessageHandler(对象大小调整的CompositionTarget)
位于System.Windows.Media.MediaContext.Resize(ICompositionTarget resizedCompositionTarget)
在System.Windows.Interop.HwndTarget.OnResize()中
在System.Windows.Interop.HwndTarget.HandleMessage(WindowMessage消息、IntPtr wparam、IntPtr lparam)
在System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr-hwnd、Int32-msg、IntPtr-wParam、IntPtr-lParam、Boolean和handled)
在MS.Win32.HwndWrapper.WndProc(IntPtr-hwnd、Int32-msg、IntPtr-wParam、IntPtr-lParam、Boolean和handled)
在MS.Win32.HwndSubclass.DispatcherCallbackOperation(对象o)上
位于System.Windows.Threading.ExceptionWrapper.InternalRealCall(委托回调、对象参数、Int32 numArgs)
位于System.Windows.Threading.ExceptionWrapper.TryCatchWhen(对象源、委托回调、对象参数、Int32 numArgs、委托catchHandler)
p、 s.如果您注释掉以下行,则在选项卡之间切换时不会出现错误:
<charting:Chart.Axes>
<charting:LinearAxis Orientation="X" Title="Value_X" ShowGridLines="True"/>
<charting:LinearAxis Orientation="Y" Title="Value_Y"/>
</charting:Chart.Axes>
但是我需要一张图表 你有没有可能在一个我可以下载的可复制的小项目中有这个?你有没有可能在一个我可以下载的可复制的小项目中有这个?
Exception Type: System.InvalidOperationException
Exception: Cannot determine the size of an axis without an orientation.
Additional information:
System.Object:
Stack Trace:
at
System.Windows.Controls.DataVisualization.Charting.DisplayAxis.GetLength(Size availableSize)
at System.Windows.Controls.DataVisualization.Charting.DisplayAxis.get_ActualLength()
at
System.Windows.Controls.DataVisualization.Charting.RangeAxis.UpdateActualRange()
at System.Windows.Controls.DataVisualization.Charting.RangeAxis.System.Windows.Controls.DataVisualization.Charting.IRangeConsumer.RangeChanged(IRangeProvider usesRangeAxis, Range`1 range)
at System.Windows.Controls.DataVisualization.Charting.DataPointSeriesWithAxes.UpdateActualIndependentAxis()
at System.Windows.Controls.DataVisualization.Charting.DataPointSeriesWithAxes.<>c__DisplayClass33.<OnDataPointsChanged>b__31()
at System.Windows.Controls.DataVisualization.Charting.DataPointSeries.<>c__DisplayClass1c.<InvokeOnLayoutUpdated>b__1b(Object , EventArgs )
at System.Windows.ContextLayoutManager.fireLayoutUpdateEvent()
at System.Windows.ContextLayoutManager.UpdateLayout()
at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.Resize(ICompositionTarget resizedCompositionTarget)
at System.Windows.Interop.HwndTarget.OnResize()
at System.Windows.Interop.HwndTarget.HandleMessage(WindowMessage msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
<charting:Chart.Axes>
<charting:LinearAxis Orientation="X" Title="Value_X" ShowGridLines="True"/>
<charting:LinearAxis Orientation="Y" Title="Value_Y"/>
</charting:Chart.Axes>