WPF工具包图表和IndependentValueBinding,IndependentValuePath [英] WPF Toolkit Charting and IndependentValueBinding, IndependentValuePath
问题描述
我遇到了WPF工具箱中的图表引擎问题.
I'm facing a problem with the charting engine from the WPF toolkit.
我没有将数据移动到适当的对象模型,因此ItemSource
带有DataView
作为后援.
I haven't moved the data to a proper object model, so the ItemSource
is backed with a DataView
.
第一次尝试
<chartingToolkit:ScatterSeries x:Name="TargetSeries"
DataPointStyle="{StaticResource TargetStyle}"
ItemsSource="{Binding Path=TargetSeriesData}"
IndependentValueBinding="{Binding Path=TargetSeries_X}"
DependentValueBinding="{Binding Path=TargetSeries_X}" />
之所以崩溃,是因为我认为绑定被视为绘图的值或某种不匹配.
This crashes because I believe the bindings are considered as the values to the plot or some sort of mismatch.
第二次尝试
<chartingToolkit:ScatterSeries x:Name="TargetSeries"
DataPointStyle="{StaticResource TargetStyle}"
ItemsSource="{Binding Path=TargetSeriesData}"
IndependentValuePath="{Binding Path=TargetSeries_X}"
DependentValuePath="{Binding Path=TargetSeries_X}" />
此崩溃发生在初始化步骤中,因为Path属性不具有依赖项属性,因此无法绑定.
This crash happens during the initialization step because the Path properties aren't backed with dependency properties and therefore cannot be bound.
第三次尝试
<chartingToolkit:ScatterSeries x:Name="TargetSeries"
DataPointStyle="{StaticResource TargetStyle}"
ItemsSource="{Binding Path=TargetSeriesData}"
IndependentValuePath="targetFooXColumnName"
DependentValuePath="targetFooYColumnName" />
现在这行得通了!
但是我想使用绑定,以便可以从使用targetFooXColumnName
切换到targetFooBarXColumnName
.因此,此解决方案将导致大量看上去很骇人的代码来手动切换路径.
Now this works!
But I wanted to use the binding so I can switch from using the targetFooXColumnName
to the targetFooBarXColumnName
. So this solution will cause a whole lot of hacky looking code to switch the Path manually.
是否可以解决此问题?我可以使用某种转换器来获取Binding属性,以正确地从DataView的列中提取数据吗?
Is there a way to fix this? Can I use some sort of converter to get the Binding properties to correctly pull the data from the columns in the DataView?
谢谢, 乔尔
推荐答案
我认为您的应用程序崩溃的原因是您尚未将数据移至适当的对象模型"
I think your application crashing on reason is "you haven't moved the data to a proper object model"
我可以尝试在ScatterSeries中进行Binding来避免崩溃:像
i can try Binding in ScatterSeries its working with out crashes: Like
<Grid Name="grid_Sample" Loaded="grid_Sample_Loaded">
<DVC:Chart Canvas.Top="80" Canvas.Left="10" Name="mcChart"
Width="400" Height="250"
Background="LightSteelBlue">
<DVC:Chart.Series>
<DVC:ScatterSeries x:Name="TargetSeries"
ItemsSource="{Binding sampleList}"
IndependentValueBinding="{Binding Path=TargetSeries_X}"
DependentValueBinding="{Binding Path=TargetSeries_Y}">
</DVC:ScatterSeries>
</DVC:Chart.Series>
</DVC:Chart>
</Grid>
private void grid_Sample_Loaded(object sender, RoutedEventArgs e)
{
sampleList = new ObservableCollection<SampleTest>() {
new SampleTest(){TargetSeries_X=20,TargetSeries_Y=50},
new SampleTest(){TargetSeries_X=25,TargetSeries_Y=60},
new SampleTest(){TargetSeries_X=30,TargetSeries_Y=50},
new SampleTest(){TargetSeries_X=40,TargetSeries_Y=60}
};
((ScatterSeries)mcChart.Series[0]).ItemsSource = sampleList;
}
根据我的知识,请尝试使用正确的模型将ItemsSource绑定到ScatterSeries.
According to My Knowledge please try with Proper model for binding ItemsSource to ScatterSeries.
这篇关于WPF工具包图表和IndependentValueBinding,IndependentValuePath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!