Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Maybe this is a silly question, but I can't seem to find the answer.

 

How can I use WPF Databinding (Datacontext) to bind to an existing business object?

 

I have seen plenty of examples that impliment INotifyPropertyChanged, how can I databind if I cannot change these objects to impliment this interface?

 

TIA

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted

Ideally it would be two way databinding.

 

I'm looking for anything to get me started using my existing objects.

 

As a side note for future projects, I'd be interested in how I should be writing my business objects for future so that they will support WPF databinding.

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted

From the MSDN Documentation it looks like I need to impliment Dependency Properties in order to achieve true databinding functionallity.

 

This is the sample code that is provided from MSDN:

 

public static readonly DependencyProperty IsSpinningProperty = 
   DependencyProperty.Register(
   "IsSpinning", typeof(Boolean),
...
   );

public bool IsSpinning
{
   get { return (bool)GetValue(IsSpinningProperty); }
   set { SetValue(IsSpinningProperty, value); }
}

 

Do me this seems like double work, am I missing something? It looks like all that happens is the Dependency Property replaces the local variable I would have used, but instead now I must do extra converting in my get/set blocks.

 

I'd appreciate other's thoughts on this.

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

  • Administrators
Posted
It does initially seem a bit more work, however in the long run WPF does provide a lot more functionality for you if you implement dependency properties. e.g. A designer using Expression could attach an animation that is triggered by your property changing or an animation could modify your property on completion...

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

So in general there is not a more elegant version of the code I posted from MSDN?

 

Is there any performance loss by doing things this way?

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

  • 3 months later...
Posted
Maybe this should be a new thread, but what is the difference between these Dependency Properties and using INotifyPropertyChanged?

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...