Search code examples
silverlightpropertiesuser-controlstextboxexpression-blend

Silverlight: How do i assign a usercontrol's property value to a textbox?


I have a user control which i have added to an outer form in silverlight. The user control has a textbox called txtRoleTitle, i have declared a property in the usercontrol's class called lableName and assigned txtRoleTitle.text to labelName as shown in the code below bellow, in the silverlight property panel, under the miscellaneous menu, i have set labelName to "Landlord", then added another one of this user control to the outerform and set its labelName to Tenant. But this does not seem to work when i run the silverlight dialogue. The value of the labelName does not appear in the textbox during design and run time.

Here is my code below. thanks

public partial class UserRoleDetails : UserControl
{
    public string labelName { get; set; }

    public UserRoleDetails()
    {
        InitializeComponent();

        this.txtRoleTitle.Text = labelName;
    }

}


Solution

  • I had a look at dependancy property solution. Although while this may work if implemented properly, for what i am trying to do, this is an overkill solution. So i have a simple solution that works now, see code below:

    public partial class UserRoleDetails : UserControl
    {
        public string labelName
        {
            get {return this.txtRoleTitle.Text;}
            set {this.txtRoleTitle.Text = value;}
        }
    
        public UserRoleDetails()
        {
            InitializeComponent();
        }
    }