使用ItemControl,DataTemplate和Visifire Charts时遇到问题。
首先,XAML中的代码如下
<DataTemplate x:Key="markerChartTemplate">
<vc:Chart Height="200" Theme="Theme1" Style="{StaticResource ChartStyle}">
<vc:Chart.Series>
<vc:DataSeries RenderAs="Line" LightWeight="true" ShadowEnabled="false" LightingEnabled="false" MarkerSize="4" LineThickness="1" DataPoints="{Binding _xAxisCollection}" />
<vc:DataSeries RenderAs="Line" LightWeight="true" ShadowEnabled="false" LightingEnabled="false" MarkerSize="4" LineThickness="1" DataPoints="{Binding _yAxisCollection}" />
<vc:DataSeries RenderAs="Line" LightWeight="true" ShadowEnabled="false" LightingEnabled="false" MarkerSize="4" LineThickness="1" DataPoints="{Binding _zAxisCollection}" />
</vc:Chart.Series>
</vc:Chart>
</DataTemplate>
<ScrollViewer HorizontalScrollBarVisibility="Disabled" HorizontalAlignment="Stretch" VerticalScrollBarVisibility="Auto">
<ItemsControl VerticalAlignment="Stretch" HorizontalAlignment="Stretch" ItemsSource="{Binding Path=_markerChartsCollections}" ItemTemplate="{StaticResource markerChartTemplate}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</ScrollViewer>
_markerChartsCollections
定义为
public ObservableCollection<My3DLineChartObject> _markerChartsCollections
在ViewModel和Model中。
现在,在模型中,我初始化了两个My3DLineChartObject
个对象并将其放入_markerChartsCollections
。
结果是我可以在_markerChartsCollections中看到两个与My3DLineChartObject相同的数字。但是,My3DLineChartObject中的属性(包括_xAxisCollection,_yAxisCollection和_zAxisCollection)无法显示。
任何人都可以帮忙看看可能的原因是什么?
输出信息是
'SkeletonMarkerCapture.vshost.exe' (CLR v4.0.30319: SkeletonMarkerCapture.vshost.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework.Aero2\v4.0_4.0.0.0__31bf3856ad364e35\PresentationFramework.Aero2.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SkeletonMarkerCapture.vshost.exe' (CLR v4.0.30319: SkeletonMarkerCapture.vshost.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_32\Microsoft.Kinect\v4.0_2.0.0.0__31bf3856ad364e35\Microsoft.Kinect.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SkeletonMarkerCapture.vshost.exe' (CLR v4.0.30319: SkeletonMarkerCapture.vshost.exe): Loaded 'C:\Users\admin\Desktop\Hand\SkeletonMarkerCapture_Good_2\SkeletonMarkerCapture\bin\Debug\AForge.Imaging.dll'. Cannot find or open the PDB file.
'SkeletonMarkerCapture.vshost.exe' (CLR v4.0.30319: SkeletonMarkerCapture.vshost.exe): Loaded 'C:\Users\admin\Desktop\Hand\SkeletonMarkerCapture_Good_2\SkeletonMarkerCapture\bin\Debug\Emgu.CV.dll'. Module was built without symbols.
'SkeletonMarkerCapture.vshost.exe' (CLR v4.0.30319: SkeletonMarkerCapture.vshost.exe): Loaded 'C:\Users\admin\Desktop\Hand\SkeletonMarkerCapture_Good_2\SkeletonMarkerCapture\bin\Debug\Emgu.Util.dll'. Module was built without symbols.
'SkeletonMarkerCapture.vshost.exe' (CLR v4.0.30319: SkeletonMarkerCapture.vshost.exe): Loaded 'C:\Users\admin\Desktop\Hand\SkeletonMarkerCapture_Good_2\SkeletonMarkerCapture\bin\Debug\AForge.dll'. Cannot find or open the PDB file.
The thread 0x75d4 has exited with code 259 (0x103).
'SkeletonMarkerCapture.vshost.exe' (CLR v4.0.30319: SkeletonMarkerCapture.vshost.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework-SystemXmlLinq\v4.0_4.0.0.0__b77a5c561934e089\PresentationFramework-SystemXmlLinq.dll'. Cannot find or open the PDB file.
'SkeletonMarkerCapture.vshost.exe' (CLR v4.0.30319: SkeletonMarkerCapture.vshost.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework-SystemXml\v4.0_4.0.0.0__b77a5c561934e089\PresentationFramework-SystemXml.dll'. Cannot find or open the PDB file.
'SkeletonMarkerCapture.vshost.exe' (CLR v4.0.30319: SkeletonMarkerCapture.vshost.exe): Loaded 'C:\Users\admin\Desktop\Hand\SkeletonMarkerCapture_Good_2\SkeletonMarkerCapture\bin\Debug\GalaSoft.MvvmLight.dll'. Symbols loaded.
'SkeletonMarkerCapture.vshost.exe' (CLR v4.0.30319: SkeletonMarkerCapture.vshost.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\UIAutomationTypes\v4.0_4.0.0.`enter code here`0__31bf3856ad364e35\UIAutomationTypes.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
答案 0 :(得分:0)
我包括下面我的原始答案中的评论,但是稍微使用Visifire之后,你可能会遇到图书馆设计的问题(几年前我开始记得这个问题) 。在图表上公开的许多DependencyProperties都无法绑定。我找到了一个像你一样的例子并发布了它here。具体而言,与DataPoints的绑定在内部进行管理。你真正想要的是绑定DataSource。即使您在ViewModel 中使用其DataPoint类型,您也需要设置YValue映射。
例如,您的DataTemplate需要更像这样的
绑定您的点集合<DataTemplate x:Key="MarkerChartTemplate">
<vc:Chart Height="200" Width="400">
<vc:Chart.Series>
<vc:DataSeries RenderAs="Line" DataSource="{Binding XAxisCollection}">
<vc:DataSeries.DataMappings>
<vc:DataMapping MemberName="YValue" Path="YValue"/>
</vc:DataSeries.DataMappings>
</vc:DataSeries>
</vc:Chart.Series>
</vc:Chart>
</DataTemplate>
您应该查看Visifire docs了解更多详情。不幸的是,对于其他DependencyProperty更新在库中无效,文档并不十分明确。
您应该检查的其他事项和一般良好做法:
您似乎正在尝试使用Visifire图表来显示3系列图表的ItemsControl。有很多事情可能会出错。这是我建议看的内容。
首先,检查您的绑定是否有效。也许你已经忘了把事情公之于众。也许你的系列没有展示,因为他们没有通知属性,而你最初绑定时也没有设置它们。拥有一个复杂的DataTemplate只是首先要做的事情,所以尝试更简单的东西,如
<DataTemplate x:Key="SimplerTemplate">
<UniformGrid Columns="3">
<TextBlock Text="{Binding _xAxisCollection}"/>
<TextBlock Text="{Binding _yAxisCollection}"/>
<TextBlock Text="{Binding _zAxisCollection}"/>
</UniformGrid>
</DataTemplate>
让我们说你这样做,你会在每个TextBlock中看到一个与Visifire.Charts.DataPointCollection对应的字符串。太棒了。这意味着您的DataBinding实际上可以正常工作。在这种情况下,我会发布更多关于你如何定义DataSeries的示例代码,以便更熟悉Visifire的人可以提供帮助(在这种情况下你应该标记Visifire)。
但是,让我们说它不起作用。您可以在Visual Studio(输出窗口)中查看一个有用的东西。还有一些方法可以使您的程序更容易调试。
希望有所帮助。