0

希望有人可以帮助解决一些令人沮丧的问题。

我有一个图表(visifire),但只是将其视为标准的 silverlight 数据绑定控件。

当尝试直接绑定到包含从 INotifyPropertyChanged 继承的对象列表<> 的我的 POCO 对象时,绝对不会发生任何事情!

在此我的字典条目类

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

然后我创建一个列表并将其放入一个名为 ClosedSameDayList 的 POCO 类中。数据填充得很好,我已经检查过了。

最终设置数据上下文时,什么也没有发生!

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>

特此关闭同一天的代码

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

2 回答 2

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; 
} 
于 2012-03-09T08:02:03.023 回答
0

尝试Visifire示例区域中的“DataBinding 快速入门”示例应用程序。

于 2012-02-27T16:54:52.260 回答