Click here to Skip to main content
15,895,779 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey guys, basically what I have are some textboxes that I need to bind to a particular data source. For example, I have a First Name textbox, but I need it to bind to only the column from my MySQL database table that has that same column name (e.g. First Name to FirstName). I set up my UI through some basic XAML, and I simply don't know where to go from here.

On my website http://www.nppetre.com I have attached a ss of my UI demonstrating what I need.

Also, I am not sure where to put this added code within my XAML.
In my <canvas> I have declared this textbox:
<TextBox Canvas.Left="93" Canvas.Top="8" Height="23" x:Name="_arFirstName" Width="120" IsReadOnly="True" />
Posted
Updated 26-Oct-10 7:34am
v3
Comments
Nish Nishant 26-Oct-10 13:45pm    
I have updated my answer based on your edited question.

I would very strongly suggest that you use some form of MVVM here. Directly binding to a DB class is not recommended. This is a good starting point:

http://msdn.microsoft.com/en-us/magazine/dd419663.aspx[^]

Also check out MVVM tutorials from Sacha and Pete here on Code Project. They are pretty good write-ups on the topics.

Edit/Update
------------

Okay based on your updated question, you can do this:

XML
<TextBox Binding="{Binding FirstName}" Canvas.Left="93" Canvas.Top="8" Height="23" x:Name="_arFirstName" Width="120" IsReadOnly="True" />.


This assumes you've already set the DataContext appropriately.
 
Share this answer
 
v4
Comments
NPP83 26-Oct-10 13:02pm    
I am operating through a domain (business object) of the corresponding type name. It isn't a direct link. The insert and update queries done through the textbox to the column are through that domain class. Is this what you are referring to?
Nish Nishant 26-Oct-10 13:05pm    
Corresponding to the DB column, the business object should ideally have a matching public property. If you have that, then it's trivial to bind the TextBox to this property. If you don't, I assume it won't be too complicated to add such a property.
NPP83 26-Oct-10 13:25pm    
In the Agent business class/domain object FirstName does have a corresponding public property. Why would it be trivial to bind to the property then if the property is the only intermediary between the textbox and the data column?
Nish Nishant 26-Oct-10 13:28pm    
If there is a FirstName property, then all you need to do is do something like Text="{Binding FirstName}".
NPP83 26-Oct-10 13:36pm    
Is this declared within the XAML where the textbox resides? I guess what I am even more confused about is how to associate the name of the textbox (in this case: _arFirstName) with the binding you described.
<code><TextBox Text="{Binding FirstName}"/></code>where FirstName will be a property within your model.
 
Share this answer
 
Comments
NPP83 26-Oct-10 13:27pm    
I am not sure where to declare this piece of code then in my xaml (thats how new I am to this). I understand its linkage to the property in the domain's corresponding business object. And does TextBox "Text" refer to the name of the textbox?

In my declaration on my canvas I have this:
<textbox canvas.left="93" canvas.top="8" height="23" x:name="_arFirstName" width="120" isreadonly="True">
Would your code declaration go in after this?
NPP83 26-Oct-10 13:32pm    
Apparently my formatted code won't display in a comment box. See above in my original question for my added code.

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