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

Dynamic binding is not working while setting the dynamic expando object to label TextProperty

$
0
0

Dynamic binding is not working in Xamarin.Forms. I have created a dynamic expando object with one property “Name” and assigned value for the property. I have created a new label and bind the expando object to Label TextProperty through SetBinding method. Noted that the text will not display in Label. Please refer the below example code

Label label = new Label();
// created a new Expando object and bind the TextProperty using Expando object
dynamic newobj = new ExpandoObject();
newobj.Name = "Hello World";
label.BackgroundColor = Color.Pink;
label.SetBinding(Label.TextProperty, "Name");
label.BindingContext = newobj;

// Added label as a child of Grid
Grid mainLayout = new Grid() { VerticalOptions = LayoutOptions.FillAndExpand };
mainLayout.RowDefinitions.Add(new RowDefinition());
mainLayout.ColumnDefinitions.Add(new ColumnDefinition());
mainLayout.Children.Add(label, 0, 0);

MainPage = new ContentPage
{
    Content = mainLayout
};            

Viewing all articles
Browse latest Browse all 77050

Trending Articles



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