Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Text property automatically reset to blank value for custom user control.

maulik25itmaulik25it INMember ✭✭
edited December 2016 in Xamarin.Forms

I have developed simple user control
Here is code for user control


        <?xml version="1.0" encoding="UTF-8" ?>
        <ContentView x:Class="FixitRate.Controls.TestControl"
                <Entry Text="{Binding Text, Source={x:Reference txt}, Mode=TwoWay}" />


public partial class TestControl : ContentView
        public TestControl()

        public static BindableProperty TextProperty = BindableProperty.Create (
                                                            propertyName: "Text",
                                                            returnType: typeof(string),
                                                            declaringType: typeof(TestControl),
                                                            defaultValue: "",
                                                            defaultBindingMode: BindingMode.TwoWay,
                                                            propertyChanged: HandleButtonPropertyChanged);

        private static void HandleButtonPropertyChanged(BindableObject bindable, object oldValue, object newValue)
            //var button = (ExtendedButton)bindable;

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

And here is code for my page
<ctr:TestControl Text="{Binding Model.UserName}" />

Here is my model code

public class LoginModel : MVVMBase
        #region Propeties
        private string _userName;
        public string UserName
            get { return _userName; }
                _userName = value;

        private string _password = string.Empty;
        public string Password
            get { return _password; }
                SetProperty<string>(ref _password, value);

        public LoginModel()


When I run a program and try to type some text, It will automatically a rest value to blank.

I put a break point in "HandleButtonPropertyChanged" and checked, First time method raised for set correct value and then second time method raised for reset blank value. I dont know why this happening.

Best Answer


Sign In or Register to comment.