Hi,
I'm working on a MAUI application for Android (VS 2022 17.2 Update 5, Telerik Maui 0.8).
I'm trying to use a RadCartesianChart. The data I'm binding uses child objects and that throws an NullReferenceExeption on Android but works fine on Windows. I'm not sure if this a MAUI issue or a Telerik issue.
To replicate, create a new MAUI app. Then replace MainPage.xaml with this code (slightly modified from your documentation):
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:telerikDataControls="clr-namespace:Telerik.XamarinForms.DataControls;assembly=Telerik.Maui.Controls.Compatibility"
xmlns:telerikChart="clr-namespace:Telerik.XamarinForms.Chart;assembly=Telerik.Maui.Controls.Compatibility"
xmlns:telerikListView="clr-namespace:Telerik.XamarinForms.DataControls.ListView;assembly=Telerik.Maui.Controls.Compatibility"
x:Class="MauiApp1.MainPage">
<telerikChart:RadCartesianChart MinimumHeightRequest="300">
<telerikChart:RadCartesianChart.HorizontalAxis>
<telerikChart:NumericalAxis LabelFitMode="MultiLine" />
</telerikChart:RadCartesianChart.HorizontalAxis>
<telerikChart:RadCartesianChart.VerticalAxis>
<telerikChart:NumericalAxis />
</telerikChart:RadCartesianChart.VerticalAxis>
<telerikChart:RadCartesianChart.Series>
<telerikChart:ScatterSplineSeries XValueBinding="NumericalData.XData" YValueBinding="NumericalData.YData" ItemsSource="{Binding Data1}" />
<telerikChart:ScatterSplineSeries XValueBinding="XData" YValueBinding="YData" ItemsSource="{Binding Data2}" />
</telerikChart:RadCartesianChart.Series>
</telerikChart:RadCartesianChart>
</ContentPage>
And MainPage.xaml.cs with this code:
namespace MauiApp1;
using System.Collections.ObjectModel;
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
Data1 = GetNumericData1();
Data2 = GetNumericData2();
BindingContext = this;
}
public ObservableCollection<Item> Data1 { get; set; }
public ObservableCollection<NumericalData> Data2 { get; set; }
public static ObservableCollection<Item> GetNumericData1()
{
var data = new ObservableCollection<Item>
{
new Item { NumericalData = new NumericalData { XData = 2, YData = 13 } },
new Item { NumericalData = new NumericalData { XData = 19, YData = 31 } },
new Item { NumericalData = new NumericalData { XData = 22, YData = 33 } },
new Item { NumericalData = new NumericalData { XData = 28, YData = 35 } },
new Item { NumericalData = new NumericalData { XData = 33, YData = 46 } },
new Item { NumericalData = new NumericalData { XData = 38, YData = 34 } },
new Item { NumericalData = new NumericalData { XData = 49, YData = 66 } },
new Item { NumericalData = new NumericalData { XData = 55, YData = 24 } },
new Item { NumericalData = new NumericalData { XData = 62, YData = 41 } },
};
return data;
}
public static ObservableCollection<NumericalData> GetNumericData2()
{
var data = new ObservableCollection<NumericalData>
{
new NumericalData { XData = 7, YData = 13 },
new NumericalData { XData = 19, YData = 17 },
new NumericalData { XData = 22, YData = 19 },
new NumericalData { XData = 28, YData = 21 },
new NumericalData { XData = 33, YData = 35 },
new NumericalData { XData = 38, YData = 43 },
new NumericalData { XData = 49, YData = 15 },
new NumericalData { XData = 55, YData = 21 },
new NumericalData { XData = 62, YData = 47 },
};
return data;
}
}
public class NumericalData
{
public double XData { get; set; }
public double YData { get; set; }
}
public class Item
{
public NumericalData NumericalData { get; set; }
}
Regards
Martin
Thank you for the repo code, I'm investigating now. While I do, can you try a quick test that adds a delay to the loading of data until the view is done? For example, something like this instead of using the page constructor
async override OnAppearing() { base.OnAppearing(); await Task.Delay(1000); Data1 = GetNumericData1(); Data2 = GetNumericData2(); BindingContext = this; }
I have this suspicion because App.Current.Main sometimes isn't ready for Content interaction until 200-300 milliseconds after on appearing is not ready (this is something that has affecting our Popup control and threw the same exception).
I will reply back again as soon as I've reproduced this locally and taken a closer look.
Hi Lance,
thanks for looking into the issue.
Does not help. I already tried a similar approach with a button click handler.
Regards
Martin