I have create a view to display an sfdatagrid and set binding to Columns through grid.SetBinding(SfDataGrid.ColumnsProperty, "SalesGridColumns").
SalesGridColumns returns Columns from the viewmodel
var grid = new SfDataGrid
{
AllowSorting = true,
AutoGenerateColumns = false,
ColumnSizer = ColumnSizer.Star,
SelectionMode = SelectionMode.Single,
};
grid.SetBinding(SfDataGrid.ColumnsProperty, "SalesGridColumns");
grid.SetBinding(SfDataGrid.ItemsSourceProperty, "SalesGridData");
But i get the following error
12-09 16:02:53.308 E/mono (26308):
12-09 16:02:53.308 E/mono (26308): Unhandled Exception:
12-09 16:02:53.308 E/mono (26308): System.Exception: SfDataGrid.Columns can't be null
12-09 16:02:53.308 E/mono (26308): at Syncfusion.SfDataGrid.XForms.SfDataGrid.OnColumnsPropertyChanged (Xamarin.Forms.BindableObject bindable, Syncfusion.SfDataGrid.XForms.Columns oldValue, Syncfusion.SfDataGrid.XForms.Columns newValue) [0x0001f] in <filename unknown>:0
12-09 16:02:53.308 E/mono (26308): at Xamarin.Forms.BindableProperty+<>c__DisplayClass13_0`2[TDeclarer,TPropertyType].<Create>b__1 (Xamarin.Forms.BindableObject bindable, System.Object oldValue, System.Object newValue) [0x00000] in <filename unknown>:0
12-09 16:02:53.308 E/mono (26308): at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindablePropertyContext context, System.Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent) [0x0010e] in <filename unknown>:0
12-09 16:02:53.308 E/mono (26308): at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes) [0x0014b] in <filename unknown>:0
12-09 16:02:53.308 E/mono (26308): at Xamarin.Forms.BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, Boolean fromTarget) [0x0020b] in <filename unknown>:0
12-09 16:02:53.308 E/mono (26308): at Xamarin.Forms.BindingExpression.Apply (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property) [0x0006b] in <filename unknown>:0
12-09 16:02:53.308 E/mono (26308): at Xamarin.Forms.Binding.Apply (System.Object newContext, Xamarin.Forms.BindableObject bindObj, Xamarin.Forms.BindableProperty targetProperty) [0x00042] in <filename unknown>:0
12-09 16:02:53.308 E/mono (26308): at Xamarin.Forms.BindableObject.SetBinding (Xamarin.Forms.BindableProperty targetProperty, Xamarin.Forms.BindingBase binding, Boolean fromStyle) [0x000af] in <filename unknown>:0
12-09 16:02:53.308 E/mono (26308): at Xamarin.Forms.BindableObject.SetBinding (Xamarin.Forms.BindableProperty targetProperty, Xamarin.Forms.BindingBase binding) [0x00000] in <filename unknown>:0
12-09 16:02:53.308 E/mono (26308): at Xamarin.Forms.BindableObjectExtensions.SetBinding (Xamarin.Forms.BindableObject self, Xamarin.Forms.BindableProperty targetProperty, System.String path, BindingMode mode, IValueConverter converter, System.String stringFormat) [0x0002a] in <filename unknown>:0
12-09 16:02:53.308 E/mono (26308): at ThesismBI.Views.Sales.SalesGridView..ctor () [0x00123] in M:\WORK\_vs.net\ThesisMobileProject\ThesisMobileMiddleWare\ThesismBI\ThesismBI\Views\Sales\SalesGridView.cs:96
12-09 16:02:53.308 E/mono (26308): at ThesismBI.Pages.Sales.SalesGridPage.RemoveDynamicResource (Xamarin.Forms.BindableProperty property) [0x00008] in M:\WORK\_vs.net\ThesisMobileProject\ThesisMobileMiddleWare\ThesismBI\ThesismBI\Pages\Sales\SalesGridPage.cs:20
12-09 16:02:53.308 E/mono (26308): at ThesismBI.Pages.Sales.SalesDashboardPage.SetDynamicResource (Xamarin.Forms.BindableProperty property, System.String key, Boolean fromStyle) [0x00058] in M:\WORK\_vs.net\ThesisMobileProject\ThesisMobileMiddleWare\ThesismBI\ThesismBI\Pages\Sales\SalesDashboardPage.cs:25
12-09 16:02:53.308 E/mono (26308): at ThesismBI.Pages.Sales.SalesSearchpage+<<OnAppearing>b__1_1>d.MoveNext () [0x0000f] in M:\WORK\_vs.net\ThesisMobileProject\ThesisMobileMiddleWare\ThesismBI\ThesismBI\Pages\Sales\SalesSearchpage.cs:83
12-09 16:02:53.308 E/mono (26308): --- End of stack trace from previous location where exception was thrown ---