【问题标题】:Binding to Xceed Chart绑定到 Xceed 图表
【发布时间】:2014-10-01 00:30:36
【问题描述】:

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

但是,the documentation 让我更加困惑...

上面写着

可以直接使用 DataPoints 属性设置系列的数据点,但也可以通过将 Series 类的 DataPointsSource 属性绑定到源,然后使用存储绑定信息的 BindingInfo 对象填充 DataPointBindings 来设置数据点。 DataPoint 类的单个属性。使用 BindingInfo.Binding 属性为给定的 DataPoint 属性(即 Content、Label、X 或 Y)设置 Binding 对象,并使用 BindingInfo.PropertyName 属性(其类型为 DataPointPropertyName)设置要使用绑定的属性。

所以,我的 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; }

图表显示,但从未包含任何数据。

那么,我怎样才能通过绑定来处理我的图表?

【问题讨论】:

    标签: c# wpf xaml binding


    【解决方案1】:

    这样就可以了

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

    【讨论】:

      猜你喜欢
      • 2018-07-15
      • 2018-05-17
      • 2018-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多