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

Binding to an Object/Field/Property Defined In CodeBehind

$
0
0

I'm pretty knew to data binding with Xamarin. It seems like a really powerful tool that comes at a cost of complexity. I've been reading forums for hours and cannot figure this out.

Let's say I have a class:

MyPage.xaml.cs

namespace NS
{
    public class CustomObject
    {
        public DateTime CreatedAt { get; set; } //I have tried with implementing INotifyPropertyChanged as well
    }

    public partial class MyPage
    {
        public CustomObject Instance;
        public MyPage() { }
    }
}

and xaml

MyPage.xaml

<ContentPage ... BindingContext="{Binding Instance}">

    <Label x:Name="Label1" Text="{Binding CreatedAt}"/>

</ContentPage>

My question is how do I bind the Text property of Label1 to the CreatedAt property of Instance, using xaml. I know this is really simple but maybe I will learn something fundamental here.

Many thanks for any clarity you can share!


Viewing all articles
Browse latest Browse all 91519

Trending Articles