using Xamarin.Forms; using Xamarin.Forms.Xaml; using System.Collections.ObjectModel; using Exchanges.Models.UI; using System.Threading.Tasks; using System.ComponentModel; using System.Collections.Specialized; namespace CryptoSuite.Views { [XamlCompilation(XamlCompilationOptions.Compile)] public partial class Portfolio : ContentPage, INotifyPropertyChanged { private ObservableCollection<BalanceUI> balanceList; public ObservableCollection<BalanceUI> BalanceList { get { return balanceList; } set { this.balanceList = value; RaiseBalanceListChanged("BalanceList"); } } public Portfolio() { InitializeComponent(); //BindingContext = App.handler; BalanceList = new ObservableCollection<BalanceUI>(); var balance1 = new BalanceUI(5.0m, "Test", 0.01m, "Test"); var balance2 = new BalanceUI(10.0m, "Test2", 1000.0m, "Test"); BalanceList.Add(balance1); BalanceList.Add(balance2); BindingContext = this; Task.Run(async () => { await ChangeDataTest(); }); } public async Task ChangeDataTest() { #region Test-Data await Task.Delay(7000); var temp = new ObservableCollection<BalanceUI>(); var balance3 = new BalanceUI(1.0m, "Test3", 10.0m, "Test"); var balance4 = new BalanceUI(2.0m, "Test4", 10.0m, "Test"); temp.Add(balance3); temp.Add(balance4); BalanceList.Clear(); BalanceList = temp; #endregion } public event PropertyChangedEventHandler BalanceListChanged; void RaiseBalanceListChanged(string propertyName) { if(BalanceListChanged != null) BalanceListChanged(this, new PropertyChangedEventArgs(propertyName)); } } } |
Portfolio.xaml:
<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:chart="clr-namespace:Syncfusion.SfChart.XForms;assembly=Syncfusion.SfChart.XForms" x:Class="CryptoSuite.Views.Portfolio"> <ContentPage.Content> <StackLayout x:Name="Stack"> <chart:SfChart x:Name="Chart" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"> <chart:SfChart.Legend> <chart:ChartLegend IconHeight="14" IconWidth="14" OverflowMode="Wrap" DockPosition="Bottom" /> </chart:SfChart.Legend> <chart:SfChart.Series> <chart:DoughnutSeries x:Name="Nut" ListenPropertyChange="True" CircularCoefficient="0.80" ItemsSource="{Binding BalanceList, UpdateSourceEventName=BalanceListChanged}" XBindingPath="currency" YBindingPath="fia_balance" ExplodeOnTouch="True" LegendIcon="Circle" EnableAnimation="true" StrokeWidth="0" StrokeColor="Black"> <chart:DoughnutSeries.DataMarker> <chart:ChartDataMarker LabelContent="YValue" ShowLabel="True" MarkerColor="Black"> </chart:ChartDataMarker> </chart:DoughnutSeries.DataMarker> <chart:DoughnutSeries.ColorModel> <chart:ChartColorModel Palette="Metro" /> </chart:DoughnutSeries.ColorModel> </chart:DoughnutSeries> </chart:SfChart.Series> </chart:SfChart> </StackLayout> </ContentPage.Content> </ContentPage> |
Thanks in advance for your help.
Alexander
|
private ObservableCollection<Model> data;
public ObservableCollection<Model> Data
{
get
{
return data;
}
set
{
data = value;
RaiseBalanceListChanged("Data");
}
}
public event PropertyChangedEventHandler PropertyChanged;
void RaiseBalanceListChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
} |
|
Task.Delay(7000).Wait();
Device.BeginInvokeOnMainThread(() =>
{
BalanceList.Add(balance3);
});
…
Task.Delay(5000).Wait();
Device.BeginInvokeOnMainThread(() =>
{
BalanceList.Clear();
BalanceList = temp;
}); |
|
<SfChart x:Name="chart" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" SelectionChanging="Chart_SelectionChanging"> |
|
async void Chart_SelectionChanging(object sender, ChartSelectionChangingEventArgs e)
{
e.Cancel = true;
Navigation.PushAsync(new PortfolioDetail(App.handler.BalanceList[args.SelectedDataPointIndex]));
DoughnutChart.ExplodeIndex = -1;
} |