Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

WPF Binding To Object Not Working

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Phil Johnson - 05 Mar 2008 19:02 GMT
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="MainGrid">
       <StackPanel FlowDirection="LeftToRight">
           <TextBlock Foreground="#FFFFFFFF">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.DataContext = _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.
Signature

Regards,

Phillip Johnson (MCSD For .NET)
PJ Software Development
www.pjsoftwaredevelopment.com

not_a_commie - 05 Mar 2008 21:22 GMT
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 DependencyProperty? You should
probably invest in some WPF books to get you started.
Phil Johnson - 06 Mar 2008 08:25 GMT
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/05/wpf-data-binding-tutorial.html

The only thing different in my code is my object does not currently
implement the INotifyPropertyChanged 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.
Signature

Regards,

Phillip Johnson (MCSD For .NET)
PJ Software Development
www.pjsoftwaredevelopment.com

> 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 DependencyProperty? You should
> probably invest in some WPF books to get you started.
Phil Johnson - 06 Mar 2008 20:24 GMT
Got this one resolved....

My object I was binding to had internal properties, constructors etc.  Even
though it is in the same assembly as the form I am binding to it, the binding
did not like the internal access.

I changed the internal to public on the constructor and properties and the
binding works!

I did not get any messages about security or permission or anything.  I try
to develop with least priviledges/permissions and try to avoid public
wherever possible... might have to rethink that approach now.

Signature

Regards,

Phillip Johnson (MCSD For .NET)
PJ Software Development
www.pjsoftwaredevelopment.com

> Thanks for the response...
>
[quoted text clipped - 14 lines]
> > DataContext. Also, is UserName a DependencyProperty? You should
> > probably invest in some WPF books to get you started.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.