WPF Databinding TextBox with a property

C

Chakkaradeep

Hi All,

I have a public property,

private String _Name;
public String Name
{
get{return _Name;}
set{_Name=value;}
}

How can I bind this value Name to the TextBox field in my WPF application?

Thanks,

Regards,
Chakkaradeep
 
N

Nicholas Paldino [.NET/C# MVP]

Chakkaradeep,

There are a number of tutorials on WPF data binding if you google the
term "WPF data binding".

With the property that you have, I doubt you will be able to get full
two-way data binding, as it doesn't seem that you have any indicator as to
when your class changes. You could get one way data binding at best.

In order to implement two-way data binding, you will need to implement
the INotifyPropertyChanged interface.

Then, assuming that you aren't creating instances of your class in XAML,
you would have to set the DataContext of the TextBox field (or a containing
control) to your instance. Then, assuming you have set up the bindings
correctly in XAML to your property, the textbox should be bound to your
class property.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top