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

How to bind a object in a custom Control

$
0
0

Hi there community,
I've got a Problem with Databinding in Xamarin.
So I have this Custom Control which already has a bindable Property SelectedItem:
` public LTVLI SelectedItem
{
get => (LTVLI)GetValue(SelectedItemProperty);
set => SetValue(SelectedItemProperty, value);
}

    public static readonly BindableProperty SelectedItemProperty =
        BindableProperty.CreateAttached(
            nameof(SelectedItem),
            typeof(LTVLI),
            typeof(MyPicker),
            null,
            propertyChanged: OnSelectedItemChanged
            );
    private static void OnSelectedItemChanged(BindableObject bindable, object oldValue, object newValue)
    {
        if (bindable is MyPicker picker)
            picker.OnPropertyChanged(nameof(picker.SelectedItem));
    }

I want to bind the property Linie.Typ:
<controls:CustomControl SelectedItem="{Binding Linie.Typ}"/>

I already set the BindingContext in the Constructor:
BindingContext = this;

and Typ is of Type "SwitchItem", which I directly derived from LTVLI.
I tested with an Alert if the Property is bound, but no positive result.

Does anyone of you got an Idea what I did wrong?


Viewing all articles
Browse latest Browse all 77050

Trending Articles