gpt4 book ai didi

c# - 绑定(bind)到 Xceed Chart

转载 作者:太空宇宙 更新时间:2023-11-03 10:40:18 26 4
gpt4 key购买 nike

我正在尝试绑定(bind)到 Xceed(Wpf 工具包扩展版)中的图形控件。

然而,the documentation 让我更加困惑......

它说

The data points of a series can be set directly using the DataPoints property, but they can also be set by binding the DataPointsSource property of the Series class to a source and then populating DataPointBindings with BindingInfo objects, which store binding information for a single property of the DataPoint class. Use the BindingInfo.Binding property to set the Binding object for a given DataPoint property (i.e., Content, Label, X, or Y) and use the BindingInfo.PropertyName property (whose type is DataPointPropertyName) to set the property to use binding for.

所以,我的 XAML 是

<StackPanel.Resources>
<loc:BackupResultsViewModel x:Key="MyVm" />
<CollectionViewSource x:Key="StatusCollection" Source="{Binding Source={StaticResource MyVm}, Path=MyData}" />
</StackPanel.Resources>

<xctk:Chart Height="30" Width="300" ShowLegend="True" >
<xctk:Chart.Legend>
<xctk:Legend Dock="Left" AllowResize="False" AllowDock="True" AllowMove="True" Title="Legend"/>
</xctk:Chart.Legend>

<xctk:Chart.Areas>
<xctk:Area Title="Overall status" >
<xctk:Area.XAxis>
<xctk:Axis ShowAxisLabel="False" ShowTickLabels="False" ShowTicks="False"/>
</xctk:Area.XAxis>

<xctk:Area.YAxis>
<xctk:Axis ShowAxisLabel="False" ShowTickLabels="False" ShowTicks="False"/>
</xctk:Area.YAxis>

<xctk:Area.Series>
<xctk:Series Title="Overall status" DataPointsSource="{Binding Source={StaticResource StatusCollection}}">
<xctk:Series.Layout>
<xctk:PieLayout />
</xctk:Series.Layout>

<xctk:Series.DataPointBindings>
<xctk:BindingInfo PropertyName="Y">
<xctk:BindingInfo.Binding>
<Binding/>
</xctk:BindingInfo.Binding>
</xctk:BindingInfo>

<xctk:BindingInfo PropertyName="X">
<xctk:BindingInfo.Binding>
<Binding/>
</xctk:BindingInfo.Binding>
</xctk:BindingInfo>

<xctk:BindingInfo PropertyName="Label">
<xctk:BindingInfo.Binding>
<Binding/>
</xctk:BindingInfo.Binding>
</xctk:BindingInfo>
</xctk:Series.DataPointBindings>

</xctk:Series>
</xctk:Area.Series>
</xctk:Area>
</xctk:Chart.Areas>
</xctk:Chart>

我的代码是

public GraphViewModel()
{
this.Title = title;

var data = new DataPointsList<DataPoint>();
data.Add(new DataPoint(0, 8, "0"));
data.Add(new DataPoint(1, 4, "1"));
data.Add(new DataPoint(2, 3, "2"));
data.Add(new DataPoint(3, 2, "3"));

this.MyData = data;
}

public DataPointsList<DataPoint> MyData { get; set; }

图表显示,但没有任何数据。

那么,我怎样才能绑定(bind)以处理我的图表?

最佳答案

这样做

  <!-- ... -->

<xctk:BindingInfo PropertyName="Y">
<xctk:BindingInfo.Binding>
<Binding Path="Y"/> <!--NOTE-->
</xctk:BindingInfo.Binding>
</xctk:BindingInfo>

<xctk:BindingInfo PropertyName="X">
<xctk:BindingInfo.Binding>
<Binding Path="X"/><!--NOTE-->
</xctk:BindingInfo.Binding>
</xctk:BindingInfo>

<xctk:BindingInfo PropertyName="Label">
<xctk:BindingInfo.Binding>
<Binding Path="Label"/><!--NOTE-->
</xctk:BindingInfo.Binding>
</xctk:BindingInfo>
</xctk:Series.DataPointBindings>

关于c# - 绑定(bind)到 Xceed Chart,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25580129/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com