我的图表中没有显示任何内容,我的数据绑定有问题吗?

时间:2012-03-17 13:51:56

标签: c# windows-phone-7 amcharts

我有以下XAML:

                    <amq:SerialChart Grid.Column="0" Grid.Row="0" DataSource="{Binding Data}" CategoryValueMemberPath="Date"
                         AxisForeground="White"
                         PlotAreaBackground="Black"
                         GridStroke="DarkGray">
                        <amq:SerialChart.Graphs>
                            <amq:LineGraph ValueMemberPath="Downfall" Title="Downfall" Brush="Blue" />
                        </amq:SerialChart.Graphs>
                    </amq:SerialChart>

我的代码看起来像这样:

namespace DownfallControl
{
    public partial class MainPage : PhoneApplicationPage
    {
        private ObservableCollection<DownfallLog> Data = new ObservableCollection<DownfallLog>()
        {
            new DownfallLog() { Date = new DateTime(2012, 2, 2), Downfall = 90.1 },
            new DownfallLog() { Date = new DateTime(2012, 2, 3), Downfall = 89.6 },
            new DownfallLog() { Date = new DateTime(2012, 2, 4), Downfall = 85.6 }
        };

        public MainPage()
        {
            InitializeComponent();
        }

        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            this.DataContext = this;

            Data.Add(new DownfallLog() { Date = new DateTime(2012, 2, 6), Downfall = 85.6 });
        }        
    }

    public class DownfallLog
    {
        public double Downfall;
        public DateTime Date;
    }
}

为什么没有出现任何线索?

1 个答案:

答案 0 :(得分:1)

ObservableCollection必须是公开的和财产,所以:

   private ObservableCollection<DownfallLog> Data = new ObservableCollection<DownfallLog>()
    {
        new DownfallLog() { Date = new DateTime(2012, 2, 2), Downfall = 90.1 },
        new DownfallLog() { Date = new DateTime(2012, 2, 3), Downfall = 89.6 },
        new DownfallLog() { Date = new DateTime(2012, 2, 4), Downfall = 85.6 }
    };

应该是这样的:

   public ObservableCollection<DownfallLog> Data {get;set;}

您可以在构造函数中初始化集合。

这些也必须是属性:

   public class DownfallLog
   {
      public double Downfall {get;set;}
      public DateTime Date   {get;set;}
   }