Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<TextBox binding="{Binding FirstName}" canvas.left="93" canvas.top="8" height="23" x:name="_arFirstName" width="120" isreadonly="True" xmlns:x="#unknown" /> 

The above is a piece of XAML code to which I added Binding to a Property which exists only in my domain object. Incidentally where it says Textbox "Binding" and getting an error that says: The property Binding was not found in type 'TextBox'. What am I missing to get this to refer to my domain object property in my C# code?

Thanks.

*Note* Not all of my snippet was transferred property. The first part does indicate that it is a TextBox
Posted
Updated 26-Oct-10 10:16am
v4
Comments
Nish Nishant 26-Oct-10 16:16pm    
I've fixed the formatting so your code snippet shows in its totality :-)

1 solution

In your Window's constructor or Load event, you need to set the data-context to your business-object.

C#
this.DataContext = yourBusinessObject;


And it's assumed that yourBusinessObject will have the FirstName property in it.
 
Share this answer
 
v2
Comments
NPP83 26-Oct-10 16:17pm    
Okay. So my class is Agent. It has a property in it called "FirstName". On formload then I need a declaration like this: this.DataContext = Agent; Right?
Nish Nishant 26-Oct-10 16:19pm    
You need an instance of Agent there. Something like

this.DataContext = new Agent(...);

or

this.DataContext = someOtherInstance.GetAgent(...);
NPP83 26-Oct-10 16:33pm    
Since my UI is in XAML/WPF, how do I instantiate a new Form Load method to insert this.DataContext?
Nish Nishant 26-Oct-10 16:51pm    
Put it in the constructor, after the call to InitializeComponent().

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