希望有人可以帮助解决一些令人沮丧的问题。
我有一个Graph(visifire),但只是将其视为标准的silverlight数据绑定控件。
尝试直接绑定到包含List<>的POCO对象时从INotifyPropertyChanged继承的对象(自定义),绝对没有任何反应!
这里是我的词典词类
class GraphValue : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string name;
public string IndicatorName
{
get
{
return name;
}
set
{
name = value;
onPropertyChanged(this, "IndicatorName");
}
}
private double _value;
public double IndicatorValue
{
get
{
return _value;
}
set
{
_value = value;
onPropertyChanged(this, "IndicatorValue");
}
}
private void onPropertyChanged(object sender, string propertyName)
{
if (this.PropertyChanged != null)
{
PropertyChanged(sender, new PropertyChangedEventArgs(propertyName));
}
}
}
然后我创建了一个List,它被放在一个名为ClosedSameDayList的POCO类中。数据填写得很好,我已经检查过了。
最终设置datacontext时,没有任何反应!
MyGraph.DataContext = ClosedSameDayList.GraphValues.OrderBy(z => z.IndicatorName);
然而,这是踢球者。
执行以下操作时,一切正常:
ObservableCollection<KeyValuePair<string, double>> g = new ObservableCollection<KeyValuePair<string, double>>();
foreach (var item in ClosedSameDayList.GraphValues)
{
g.Add(new KeyValuePair<string, double>(item.IndicatorName, item.IndicatorValue));
}
MyGraph.DataContext = g.OrderBy(z => z.Key);
此处为图表的XAML:
<vc:Chart xmlns:vc="clr-namespace:Visifire.Charts;assembly=SLVisifire.Charts" DataContext="{Binding}" Name="MyGraph" Height="240" BorderThickness="0" Theme="Theme2" View3D="True" ToolBarEnabled="True" >
<vc:Chart.Titles>
<vc:Title Text="My Title" />
</vc:Chart.Titles>
<vc:Chart.AxesX>
<vc:Axis Title="My Title" />
</vc:Chart.AxesX>
<vc:Chart.AxesY>
<vc:Axis Title="My Title" AxisType="Primary" />
</vc:Chart.AxesY>
<vc:Chart.Series>
<vc:DataSeries RenderAs="Column" DataSource="{Binding}">
<vc:DataSeries.DataMappings>
<vc:DataMapping MemberName="AxisXLabel" Path="IndicatorName"></vc:DataMapping>
<vc:DataMapping MemberName="YValue" Path="IndicatorValue"></vc:DataMapping>
</vc:DataSeries.DataMappings>
</vc:DataSeries>
</vc:Chart.Series>
</vc:Chart>
此处为ClosedSameDay代码
class ClosedSameDay
{
public CamlQuery CamlQuery { get; set; }
public List List { get; set; }
public ListItemCollection Listitems { get; set; }
public List<GraphValue> GraphValues { get; set; }
public ClosedSameDay()
{
GraphValues = new List<GraphValue>();
CamlQuery = new CamlQuery();
CamlQuery.ViewXml = "<View>" +
" <Method Name='ITServicedesk_Dashboard_ClosedSameday_Individuals_Readlist'/>" +
" <Query>" +
" <OrderBy>" +
" <FieldRef Name='id'/>" +
" </OrderBy>" +
" </Query>" +
" <ViewFields>" +
" <FieldRef Name='id'/>" +
" <FieldRef Name='Name'/>" +
" <FieldRef Name='Total'/>" +
" </ViewFields>" +
"</View>";
}
public void PopulateObjectData()
{
foreach (ListItem item in Listitems)
{
double value = -1;
double.TryParse(item["Total"].ToString(), out value);
if (item["Name"] != null && !string.IsNullOrEmpty(item["Name"].ToString()) && value != -1)
{
this.GraphValues.Add(new GraphValue
{
IndicatorName = item["Name"].ToString(),
IndicatorValue = value
});
}
}
}
public DataSeries BuildDataSeries()
{
ObservableCollection<KeyValuePair<string, double>> g = new ObservableCollection<KeyValuePair<string, double>>();
foreach (var item in this.GraphValues)
{
g.Add(new KeyValuePair<string, double>(item.IndicatorName, item.IndicatorValue));
}
Visifire.Charts.DataSeries ds = new Visifire.Charts.DataSeries();
ds.RenderAs = Visifire.Charts.RenderAs.Column;
ds.DataSource = g.OrderBy(i => i.Key);
Visifire.Charts.DataMapping dm = new Visifire.Charts.DataMapping();
dm.MemberName = "AxisXLabel";
dm.Path = "Key";
ds.DataMappings.Add(dm);
Visifire.Charts.DataMapping dm2 = new Visifire.Charts.DataMapping();
dm2.MemberName = "YValue";
dm2.Path = "Value";
ds.DataMappings.Add(dm2);
return ds;
}
}
答案 0 :(得分:0)
尝试"Quick Start With DataBinding"样本申请表格Visifire Example Area.
答案 1 :(得分:0)
我关闭了这个问题。通过创建DataSeries使用下面的手动数据绑定方法,一切正常
public DataSeries BuildDataSeries()
{
ObservableCollection<KeyValuePair<string, double>> g = new ObservableCollection<KeyValuePair<string, double>>();
foreach (var item in this.GraphValues)
{
g.Add(new KeyValuePair<string, double>(item.IndicatorName, item.IndicatorValue));
}
Visifire.Charts.DataSeries ds = new Visifire.Charts.DataSeries();
ds.RenderAs = Visifire.Charts.RenderAs.Column;
ds.DataSource = g.OrderBy(i => i.Key);
Visifire.Charts.DataMapping dm = new Visifire.Charts.DataMapping();
dm.MemberName = "AxisXLabel";
dm.Path = "Key";
ds.DataMappings.Add(dm);
Visifire.Charts.DataMapping dm2 = new Visifire.Charts.DataMapping();
dm2.MemberName = "YValue";
dm2.Path = "Value";
ds.DataMappings.Add(dm2);
return ds;
}