WPF 工具包图表和 IndependentValueBinding、IndependentValuePath

发布于 2024-09-04 17:41:35 字数 1330 浏览 2 评论 0原文

我遇到了 WPF 工具包中的图表引擎的问题。

我尚未将数据移动到正确的对象模型,因此 ItemSourceDataView 支持。

第一次尝试

<chartingToolkit:ScatterSeries x:Name="TargetSeries" 
  DataPointStyle="{StaticResource TargetStyle}"  
  ItemsSource="{Binding Path=TargetSeriesData}"
  IndependentValueBinding="{Binding Path=TargetSeries_X}" 
  DependentValueBinding="{Binding Path=TargetSeries_X}" />

这会崩溃,因为我相信绑定被视为绘图的值或某种不匹配。

第二次尝试

<chartingToolkit:ScatterSeries x:Name="TargetSeries" 
  DataPointStyle="{StaticResource TargetStyle}" 
  ItemsSource="{Binding Path=TargetSeriesData}"
  IndependentValuePath="{Binding Path=TargetSeries_X}"
  DependentValuePath="{Binding Path=TargetSeries_X}" />

此崩溃发生在初始化步骤期间,因为 Path 属性没有依赖项属性支持,因此无法绑定。

第三次尝试

<chartingToolkit:ScatterSeries x:Name="TargetSeries" 
  DataPointStyle="{StaticResource TargetStyle}"  
  ItemsSource="{Binding Path=TargetSeriesData}"
  IndependentValuePath="targetFooXColumnName" 
  DependentValuePath="targetFooYColumnName" />

现在可以了! 但我想使用绑定,以便可以从使用 targetFooXColumnName 切换到使用 targetFooBarXColumnName。因此,这个解决方案将导致大量看似黑客的代码手动切换路径。

有办法解决这个问题吗?我可以使用某种转换器来获取 Binding 属性以正确从 DataView 中的列中提取数据吗?

谢谢, 乔尔

I'm facing a problem with the charting engine from the WPF toolkit.

I haven't moved the data to a proper object model, so the ItemSource is backed with a DataView.

First attempt

<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.

Second attempt

<chartingToolkit:ScatterSeries x:Name="TargetSeries" 
  DataPointStyle="{StaticResource TargetStyle}" 
  ItemsSource="{Binding Path=TargetSeriesData}"
  IndependentValuePath="{Binding Path=TargetSeries_X}"
  DependentValuePath="{Binding Path=TargetSeries_X}" />

This crash happens during the initialization step because the Path properties aren't backed with dependency properties and therefore cannot be bound.

Third attempt

<chartingToolkit:ScatterSeries x:Name="TargetSeries" 
  DataPointStyle="{StaticResource TargetStyle}"  
  ItemsSource="{Binding Path=TargetSeriesData}"
  IndependentValuePath="targetFooXColumnName" 
  DependentValuePath="targetFooYColumnName" />

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.

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?

Thanks,
Joel

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只为一人 2024-09-11 17:41:35

我认为您的应用程序崩溃的原因是“您尚未将数据移动到正确的对象模型”

我可以尝试在 ScatterSeries 中绑定其工作而不会崩溃:就像

<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。

I think your application crashing on reason is "you haven't moved the data to a proper object model"

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; 
    }

According to My Knowledge please try with Proper model for binding ItemsSource to ScatterSeries.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文