Inherit bindableproperty in contentview

Emiliano Magnani 21 Reputation points
2020-11-25T14:47:59.067+00:00

Hi everyone.

I have a working custom control. I want to have another custom control inheriting from the previous one but something is not working as expected.

In the second control oneway properties don't take the value I send from the implementation while the original control works perfectly. Looks like an issue at rendering time because if I debug a property change event I can see the values I sent in the control. Even a validation takes the default value at first but then use the value I sent.

For example this simple string property to display in a label doesn't work in DateTimeRange

public class DateRange : ContentView, IDateRange
{
   //....
   public static readonly BindableProperty FromTextProperty = BindableProperty.Create(
            propertyName: nameof(FromText),
            returnType: typeof(string),
            declaringType: typeof(DateRange),
            defaultValue: "Desde",
            defaultBindingMode: BindingMode.OneWay
            );

        public string FromText
        {
            get => (string)GetValue(FromTextProperty);
            set => SetValue(FromTextProperty, value);
        }
}



public class DateTimeRange : DateRange, INotifyPropertyChanged
{
   //....

}

Implementations:

<controls:DateRange DateTimeFrom="{Binding DateFrom}" DateTimeTo="{Binding DateTo}" Difference="10" Size="Large" LabelColumnWidth="70" FromText="From" ToText="To"/>
<controls:DateTimeRange DateTimeFrom="{Binding DateFrom}" DateTimeTo="{Binding DateTo}" Difference="2" Size="Large" LabelColumnWidth="70"  FromText="From" ToText="To"/>
Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,362 questions
0 comments No comments
{count} votes

Accepted answer
  1. acmeaney 76 Reputation points
    2020-11-25T15:29:55.753+00:00

    I would say debugging step one is to put absolutely no code in the second class, and see if it performs exactly the same as the first class.

    If not, check for some kind of style you might be implicitly applying that makes a differnence.

    Otherwise, we are going to need more code, as just having a property the inheriting class can see works fine in every case I have seen.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.