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

本文关键字:我的 有问题 数据绑定 显示 任何内 | 更新日期: 2023-09-27 18:28:03

我得到了以下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;
    }
}

知道为什么什么都没出现吗?

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

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