473,799 Members | 3,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

WPF Binding To Object Not Working

Hello,

My first attempt to bind a 'detail' form to the properties on an object and
the binding is not working.

I have the following grid:

<Grid x:Name="MainGri d">
<StackPanel FlowDirection=" LeftToRight">
<TextBlock Foreground="#FF FFFFFF">First name:</TextBlock>
<TextBox Text="{Binding Path=UserName}" ></TextBox>
</StackPanel>
</Grid>

And the code behind on the load for the form runs the following... its
definitely executing and the UserName property of _user is set to "Phillip",
but nothing displays in the text box detailed above!

this.MainGrid.D ataContext = _user;

Is there some obvious properties or calls I need to set or make to get a
simple binding app like this to work? Or am I missing something else?

Thanks.
--
Regards,

Phillip Johnson (MCSD For .NET)
PJ Software Development
www.pjsoftwaredevelopment.com
Mar 5 '08 #1
2 2074
I'm no expert on this, but I think you need to specify the object that
has the UserName property in your Binding regardless of the
DataContext. Also, is UserName a DependencyPrope rty? You should
probably invest in some WPF books to get you started.
Mar 5 '08 #2
Thanks for the response...

I've read a bit about it in Essential Windows Presentation Foundation by
Chris Anderson and I'm also looking at this tutorial....

http://coredotnet.blogspot.com/2006/...-tutorial.html

The only thing different in my code is my object does not currently
implement the INotifyProperty Changed interface, but in Chris Anderson's book
he says that's optional.

Might try implementing the interface and seeing if it binds... not too
hopeful though. If anybody has any ideas I would be grateful.
--
Regards,

Phillip Johnson (MCSD For .NET)
PJ Software Development
www.pjsoftwaredevelopment.com
"not_a_comm ie" wrote:
I'm no expert on this, but I think you need to specify the object that
has the UserName property in your Binding regardless of the
DataContext. Also, is UserName a DependencyPrope rty? You should
probably invest in some WPF books to get you started.
Mar 6 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2952
by: Jesse | last post by:
Hi All, I've been working on a form that has several bound controls that all link to one table in a dataset. In the table, there is a column for the filename of jpeg images related to each record. I have a combobox which displays the key for each record so that the user can select an item and all the other controls update. So far i have the combobox, a label and a textbox all bound and working correctly when a user selects an item. ...
9
10430
by: Zlatko Matiæ | last post by:
I was reading about late binding, but I'm not completely sure what is to be done in order to adjust code to late binding... For example, I'm not sure if this is correct: early binding: Dim ws As DAO.Workspace Dim db As DAO.Database Dim qdf As DAO.QueryDef Dim rs As DAO.Recordset
2
325
by: Boniek | last post by:
Hi, How I can create property to binding with other objects. I want to create a data object which work as a DataTable. DataTable contains columns and dataTable is used to binding with a textBox etc. How I can create that object but I don't want any static properties in source code. I implemented IDataBinding in my object but when I'm binding my TextBox to this data object than my application raise exception which tell me that my object...
19
2348
by: Simon Verona | last post by:
I'm not sure if I'm going down the correct route... I have a class which exposes a number of properties of an object (in this case the object represents a customer). Can I then use this object to databind to text boxes etc? I can't use a dataset as the object has loads of derived logic, for example updating one property may actually update several database fields for example.
2
4801
by: David Veeneman | last post by:
I want to data bind a user control and a business object, using a BindingSource control. The control has a 'Priority' property that takes a 'Priority' enum (High, Normal, Low). The business object has a property with the same name, which takes an identical enum. Data binding isn't working, and I think it's because the two enums are different. Even though they have the same name and the same elements, they are declared under different...
3
2162
by: TS | last post by:
when binding to a datagrid for example, is it possible to use databinding syntax to bind to a property of a property? Say the datasource="Cars" which is a collection of car classes and the DataValueField = "Driver.Name" which is the Car.Driver property and then the Driver.Name property. thanks
6
2451
by: Mikus Sleiners | last post by:
Is there any way to enable exception throws in VS 2005, that occur during binding operations? I am upset that i can't see exceptions that are thrown during binding operations. It's very hard to track down erroneous behaviour of your app if you can't see where the problem is... i mean it's realy hard to debug binding issues and it would be realy of help if i could somehow enable this during debug session.
9
2806
by: =?Utf-8?B?VGVycnk=?= | last post by:
Think it is great the way that you can set up a datsource, value member, and display member for a combobox, and map a 'code' to a 'description' and back again by binding the combobox to a datasource that contains the code. Now suppose that you want it to be read-only? That is, you have the 'code' in your DB, want the associated 'description' to display, but not let the user change it on this particular form. There is no read-only...
5
3949
by: =?Utf-8?B?VGVycnk=?= | last post by:
Hi, I have a couple of labels on a form and their visible property is bound to boolean properties on a custom object. When I first load the form, all works as it should. This form is 'tied' together with a search form, and the user can go back and forth. When the user hits ok, the form is hidden and the search form is shown and visa-versa. The problem is that when the form is hidden when the labels visible property is False, and then...
0
9686
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9540
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10475
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10026
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7564
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4139
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.