I'm trying to extract this Entry in a Frame into a custom element in Xamarin, to get a reusable Entry with border only on top and on bottom:
<Frame xmlns="..."
HasShadow="False"
CornerRadius="0"
Padding="0, 1, 0, 1"
BackgroundColor="#c0c0c0">
<Entry Padding="20, 10, 20, 10"
Placeholder="{Binding Placeholder}"
Text="{Binding Text}"
BackgroundColor="#ffffff" />
</Frame>
Code Behind:
public partial class CbSingleEntry : Frame
{
public static readonly BindableProperty TextProperty = BindableProperty.Create("Text", typeof(string), typeof(CbSingleEntry));
public static readonly BindableProperty PlaceholderProperty = BindableProperty.Create("Placeholder", typeof(string), typeof(CbSingleEntry));
public string Text
{
get { return (string)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
public string Placeholder
{
get { return (string)GetValue(PlaceholderProperty); }
set { SetValue(PlaceholderProperty, value); }
}
public CbSingleEntry()
{
InitializeComponent();
BindingContext = this;
}
}
When I try to use this custom field, the Placeholder and Text property are correctly set, but I can't bind them to attributes in my class:
// this one works fine
<local:CbSingleEntry Placeholder="Company" Text="My Company" />
// Placeholder works, but Text is always empty
<local:CbSingleEntry Placeholder="Company" Text="{Binding Company}" />
I can confirm that Company has a value, because with a normal text field it works correctly:
// This one works as expected, Text is displayed from binded attribute
<Entry Placeholder="Company" Text="{Binding Company}" />