Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a textbox in my xaml and a property (say First name)in xaml.cs.

Now how to bind this property to xaml textbox
Posted

Check out a sample:
XML
<usercontrol x:class="SilverlightApplication1.MainPage" xmlns:x="#unknown">
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <grid x:name="LayoutRoot" background="White">
        <textblock text="{Binding TextProperty}" height="30" width="200"></textblock>
    </grid>
</usercontrol>

Code:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightApplication1
{
    public partial class MainPage : UserControl
    {
        public string TextProperty { get; set; }

        public MainPage ()
        {
            InitializeComponent();
            TextProperty = "This is the Silverlight";
            this.DataContext = this;
        }
    }
}

Ref.: Bind Property to Textblock

Also refer: Binding.ElementName Property
 
Share this answer
 
Comments
Mahesh Kumar Badgujar 22-Jun-12 1:50am    
in xaml you wrote
<textblock text="{Binding TextProperty}" height="30" width="200">
in my case i am not getting text property here
"{Binding textProperty}"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900