Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Binding in code

$
0
0

Hi, in this documentation https://documentation.devexpress.com/#Xamarin/clsDevExpressMobileDataGridTemplateColumntopic there are example code for binding using devexpress gridcontrol. In the Xaml:MainPage.xaml tab could someone explain this binding:


<Grid BindingContext="{Binding Source}" Padding="0,15,0,15">

and how to do this in code?
I have tried the following:


templateColumn.DisplayTemplate = new DataTemplate (() => { Label firstNameLabel = new Label(); firstNameLabel.FontAttributes = FontAttributes.Bold; firstNameLabel.FontSize = 20; firstNameLabel.SetBinding(Label.TextProperty, new Binding("FirstName")); Label emailLabel = new Label(); emailLabel.SetBinding(Label.TextProperty, new Binding("Email")); Grid grid = new Grid { RowDefinitions = { new RowDefinition() { Height = GridLength.Auto }, new RowDefinition() { Height = GridLength.Auto } }, Children = { firstNameLabel, emailLabel } }; grid.SetBinding(Grid.BindingContextProperty, new Binding("Source")); return grid; });

but I keep getting this error:


System.NullReferenceException: Object reference not set to an instance of an object at at DevExpress.Mobile.DataGrid.Internal.ObjectRowData

Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>