0

Hope someone can help with a bit of a frustrating issue.

I have a Graph (visifire) but just look at it as a standard silverlight databound control.

When attempting to bind directly to my POCO Object which contains a List<> of objects (custom) which inherits from INotifyPropertyChanged, then absolutely nothing happens!

Herewith my Dictionary Entry Class

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

I then create a List and it's put inside a POCO Class called ClosedSameDayList. The data is populated fine, i've checked.

When eventually setting the datacontext, nothing happens!

MyGraph.DataContext = ClosedSameDayList.GraphValues.OrderBy(z => z.IndicatorName);

However, here's the kicker.

When doing the following, everything works :

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

Herewith the XAML for the Chart:

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

Herewith Code for 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;
        }
    }
Fox
  • 891
  • 3
  • 9
  • 30
  • Can you share the XAML so it will be easy to understand the binding settings? – Vivek Feb 27 '12 at 16:35
  • Thanks for sharing XAML. I have tried creating the same with a POCO class using latest version of Visifire. It's working well here. Which version of Visifire you are using? Can you share your code for ClosedSameDayList? – Somnath Mar 07 '12 at 08:20
  • Hi There. I'm using Visifire 4.0.0.0 . I've updated the question with the code for the ClosedSameDayList Class which is an Instance of ClosedSameDay Class. – Fox Mar 07 '12 at 10:46
  • 1
    You have added DataSeries in XAML but also adding DataSeries form code? public DataSeries BuildDataSeries()! I'm confused! Please edit your question so that it does not create confusion. I'm trying to detect what is wrong. I guess Path property was not set properly while DataMapping; According to XAML it should be dm.Path = "IndicatorName"; and next dm.Path = "IndicatorValue"; – Somnath Mar 07 '12 at 13:26
  • Thanks for trying to help Somnath. I did the DataSeries in code behind because the XAML binding didn't work. Anyways, I found a workaround, so I'm gonna stick to that. Vote up for trying to help. – Fox Mar 07 '12 at 18:27

2 Answers2

0

Try the "Quick Start With DataBinding" sample applicaion form Visifire Example Area.

Somnath
  • 3,247
  • 4
  • 28
  • 42
  • I have and for some reason it's not working. It's only when working with a POCO Object that it doesn't databind. – Fox Feb 28 '12 at 06:04
0

Im closing this Question. Using the manual databinding method below by creating a DataSeries, everything worked fine

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; 
} 
Fox
  • 891
  • 3
  • 9
  • 30