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

Bindable property not being updated

$
0
0

I have a custom control that extends from content view:

<ContentView Opacity=".8" BackgroundColor="#fafafa" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="TamarianApp.EmptyLabel">
    <StackLayout>
        <BoxView HorizontalOptions="FillAndExpand" HeightRequest="3" BackgroundColor="#f1f1f1" VerticalOptions="Start"/>
        <StackLayout HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand">
            <Label HorizontalOptions="Center" VerticalOptions="Center" TextColor="Gray" Text="{Binding Text}"/>
        </StackLayout>
    </StackLayout>
</ContentView>

Backend:

public partial class EmptyLabel : ContentView
    {
        public static BindableProperty TextProperty = BindableProperty.Create(
            "Text",
            typeof(string),
            typeof(EmptyLabel),
            defaultBindingMode: BindingMode.TwoWay,
            defaultValue: "",
            propertyChanged: TextPropertyChanged
        );


        public string Text
        {
            get
            {
                return (string)GetValue(TextProperty);
            }
            set
            {
                SetValue(TextProperty, value);
            }
        }

        public EmptyLabel()
        {
            InitializeComponent();

            BindingContext = this;
        }

        private static void TextPropertyChanged(BindableObject bindable, object oldVal, object newVal)
        {
            ((EmptyLabel)bindable).Text = newVal.ToString();
        }
    }

I want to control the visiblity of the EmptyLabel control from the view model by binding a property to it :

    ``<local:EmptyLabel IsVisible="{Binding HasNoImages}" Text="No Images"></local:EmptyLabel>``

For instance If I changed IsVisible="{Binding HasNoImages}" toIsVisible="false" it works.

Everything else on the page binds to there controls ( theres a lot more code ), but when binding to the custom control from the binding context, it ignores it. What is happening here?


Viewing all articles
Browse latest Browse all 89864

Trending Articles



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