In short, I have a custom control in Xamarin for which I defined a BindableProperty, which I would like to bind to the control's xaml via a calculated property in the code behind, but it always displays as null because the calculated property is evaluated when the BindableProperty didn't have a value yet, and afterward I am missing property changed notification logic. Which is the right way to do it?
Long explanation for context:
I am writing a custom control in Xamarin (which I named
Код: Выделить всё
TabbedLayout
Код: Выделить всё
Код: Выделить всё
public static readonly BindableProperty TabContentsProperty = BindableProperty.Create(
nameof(TabContents),
typeof(View[]),
typeof(TabbedLayout),
null,
BindingMode.OneWay);
public View[] TabContents
{
get => (View[])GetValue(TabContentsProperty);
set => SetValue(TabContentsProperty, value);
}
Код: Выделить всё
int SelectedIndex = 0
I have then created a calculated property like so:
Код: Выделить всё
public View DisplayedElement = TabContents?.ElementAt(SelectedIndex);
Код: Выделить всё
From here, how would I update the view as soon as the BindableProperty value is set, the first time and every time it might be modified, to trigger a refresh of the bound DisplayedElement property?
Источник: https://stackoverflow.com/questions/781 ... ode-behind