简体   繁体   English

Silverlight 图表,在运行时更改绑定属性?

[英]Silverlight chart, change binding property at run time?

first off the example code, I have a class like so首先关闭示例代码,我有一个 class 像这样

Public class SomeClass
{
  Public int indexNum {get;set;}
  Public int value1 {get;set;}
  Public int value2 {get;set;}

  Public SomeClass(){}
}

I create a list and fill it.我创建一个列表并填写它。

List<SomeClass> AList = new List<SomeClass>();

for(int i =0; i < 5; i++)
{
  AList.Add(new SomeClass()
      {
        indexNum = i,
        Value1 = i * 5,
        Value2 = i * 2
      });
}

MyChart.DataContext = AList;

and the binding in the chart like so和图表中的绑定一样

DependentValueBinding="{Binding Value1}" IndependentValueBinding="{Binding indexNum}"

Now on the page there will be a button at the top.现在在页面顶部会有一个按钮。 When I push the button I would like the DependentValueBinding to switch from Value1 to Value2.当我按下按钮时,我希望 DependentValueBinding 从 Value1 切换到 Value2。 Can this all be done in the xaml code or do I have to create all the bindings in the code behind?这一切都可以在 xaml 代码中完成,还是我必须在后面的代码中创建所有绑定?

You can use XamlWriter.Save method to serialize an object.您可以使用XamlWriter.Save方法序列化 object。

And you can use XamlReader.Load method to deserialize the a XAML string.您可以使用XamlReader.Load方法反序列化 XAML 字符串。

I couldn't find how to do all this in xaml but in code behind its just as simple as this我在 xaml 中找不到如何完成所有这些操作,但在其背后的代码中就这么简单

((ColumnSeries)MyChart.Series[0]).DependentValueBinding = 
   new System.Windows.Data.Binding("Value2");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM