Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF Itemcontrol和datatemplate未正确显示_C#_Wpf_Datatemplate_Itemsource_Visifire - Fatal编程技术网

C# WPF Itemcontrol和datatemplate未正确显示

C# WPF Itemcontrol和datatemplate未正确显示,c#,wpf,datatemplate,itemsource,visifire,C#,Wpf,Datatemplate,Itemsource,Visifire,我在使用ItemControl、DataTemplate和Visifire图表时遇到问题 首先,XAML中的代码如下 <DataTemplate x:Key="markerChartTemplate"> <vc:Chart Height="200" Theme="Theme1" Style="{StaticResource ChartStyle}"> <vc:Chart.Series> <vc:DataSe

我在使用ItemControl、DataTemplate和Visifire图表时遇到问题

首先,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>
在ViewModel和Model中

现在,在模型中,我初始化了两个
My3DLineChartObject
对象,并将其放入
\u 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.

我在下面列出了我的原始答案中的注释,但是在玩了一点Visifire之后,您可能在库的设计上遇到了问题(我从几年前使用它开始记得这一点)。图表上公开的许多DependencyProperties无法绑定到。我想出了一个像你这样的例子,并把它贴了出来。具体来说,与数据点的绑定是在内部管理的。您真正想要的是绑定数据源。即使在ViewModel中使用YValue映射的数据点类型,也需要设置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>

你应该看一看更多的细节。不幸的是,文档并没有明确说明库中其他DependencyProperty更新无效


您应该检查的其他事项和一般良好做法:

看起来您正试图使用Visifire图表显示一个由3个系列图表组成的Items控件。有很多事情可能会出错。以下是我的建议

首先,检查绑定是否正常工作。也许你忘了把什么公之于众。可能您的系列没有显示,因为它们没有通知属性,并且您在初始绑定时没有设置它们。拥有一个复杂的数据模板一开始只会让事情变得复杂,所以尝试一些更简单的方法,比如

<DataTemplate x:Key="SimplerTemplate">
    <UniformGrid Columns="3">
        <TextBlock Text="{Binding _xAxisCollection}"/>
        <TextBlock Text="{Binding _yAxisCollection}"/>
        <TextBlock Text="{Binding _zAxisCollection}"/>
    </UniformGrid>
</DataTemplate>

假设您这样做了,并且在每个文本块中看到一个字符串,该字符串对应于Visifire.Charts.DataPointCollection。太好了。这意味着您的数据绑定将实际工作。在这种情况下,我将发布更多关于如何定义数据系列的示例代码,以便更熟悉Visifire的人可以提供帮助(在这种情况下,您也应该标记Visifire)

但是,假设它不起作用。您可以在VisualStudio(您的输出窗口)中检查一件有用的事情。还有一些方法可以使您的程序更易于调试

  • 检查控制台输出是否存在System.Windows.Data绑定错误。如果有输入错误或您的字段不可访问,WPF将记录一个错误
  • 不要绑定到原始字段。将您的可观察收集设置为私有和只读。用吸气剂包起来。您希望确保您的其他代码,尤其是XAML中定义的数据绑定,都不会在后台交换您的集合。对于双向绑定,犯这样的错误并不难
  • 在My3DLineChartObject上,同样的,用getter属性包装您的三个系列并绑定到它们
  • 在ViewModel和My3DLineChartObject上实现INotifyPropertyChanged。无论何时更改My3DLineChartObject中的一个系列字段,您都需要引发NotifyPropertyChanged(“…AxisCollection”)。如果您从未更改它们,那么应该将它们设置为只读,并提供一个getter。同样,这避免了它们被双向绑定替换掉
  • 在AxisCollection获取程序中放置断点。当您运行应用程序并显示此视图时,是否调用了这些getter?数据绑定使用反射,它将调用getter属性

希望有帮助

确保它们是公共属性,而不是字段/members检查输出窗口中运行时发生的数据绑定错误,并将它们添加到此处。如果已附加输出窗口,请执行以下操作。我看不到任何与数据绑定相关的错误。嗨,timmyl,谢谢你的评论。我将SimpleTemplate放入我的代码中,并得到与三个DataPointCollection相对应的(Collection)(Collection)(Collection)。这是你期待的吗?谢谢。是的,听起来你的绑定工作正常。我认为这个问题可能与Visifire库有关。它们不支持直接绑定数据点属性。看看我在这里举的例子:嗨,timmyl,谢谢你的代码。我想它现在起作用了。
<DataTemplate x:Key="SimplerTemplate">
    <UniformGrid Columns="3">
        <TextBlock Text="{Binding _xAxisCollection}"/>
        <TextBlock Text="{Binding _yAxisCollection}"/>
        <TextBlock Text="{Binding _zAxisCollection}"/>
    </UniformGrid>
</DataTemplate>