Xamarin为Microchart

时间:2018-01-14 11:05:19

标签: listview data-binding charts xamarin.forms

我有一个连接到ObservableCollection的工作ListView(PeopleList),并希望使用Microchart显示ListView中每个项目的图形。这是可能的,你将如何在代码中绑定和更新图表?我是Xamarin的新手。

XML

<ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
 <Button Text="{Binding Kicks, Mode=TwoWay}" Clicked="KickClicked" CommandParameter="{Binding .}" HorizontalOptions="CenterAndExpand" BackgroundColor="Blue" Margin="0" FontSize="Small" Grid.Row="1" Grid.Column="1" TextColor="White"/>
   <Button Text="{Binding Marks,Mode=TwoWay}" Grid.Row="1" Grid.Column="3"  CommandParameter="{Binding .}" Clicked="KickClicked" HorizontalOptions="CenterAndExpand" BackgroundColor="DarkSlateGray" TextColor="White"/>

<forms:ChartView HeightRequest="150" Grid.Row="2" Grid.Column="1" Chart="{Binding ChartData}" />   ....

代码隐藏

 public async void LoadAll()
    {
    DateTime GameToday = DateTime.Now.Date;
    ObservableCollection<Person> people =
        new ObservableCollection<Person>(
            await App.PersonRepo.GetAllPeopleAsync());
    PeopleList.ItemsSource = people.Where(Date => Date.Date == GameToday);
    //PeopleList.IsGroupingEnabled = true;
   //var Values = people.Where(Date => Date.Date == GameToday);
    }

    public async void KickClicked(object sender, EventArgs e)
    {
        var item = (Xamarin.Forms.Button)sender;

        var player = item.CommandParameter as Person;


        item.Text = Convert.ToString((Int32.Parse(item.Text) + 1));
        await item.ScaleTo(0.75, 50, Easing.CubicOut);
        await item.ScaleTo(1, 90, Easing.CubicIn);
        //if (callback != null)
        //    callback.Invoke();
        await App.PersonRepo.UpdateAllAsync(player);

    }

模型

namespace People.Models
{
[Table("people")]
public class Person : INotifyPropertyChanged
{
    [SQLite.PrimaryKey, SQLite.AutoIncrement]
    public int Id { get; set; }

    [MaxLength(250)]
    public string Name { get; set; }
    public string GNumber { get; set; }


    public DateTime Date { get; set; }

    private int kicks;
    public int Kicks
    {
        get { return kicks; }
        set
        {
            this.kicks = value;
            OnPropertyChanged(nameof(Kicks));
        }
    }

public event PropertyChangedEventHandler PropertyChanged;

    private void OnPropertyChanged(string propertyName)
    {
        this.PropertyChanged?.Invoke(this,
          new PropertyChangedEventArgs(propertyName));
    }
}
}

0 个答案:

没有答案