Nate Bross Posted September 4, 2008 Posted September 4, 2008 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 Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Administrators PlausiblyDamp Posted September 8, 2008 Administrators Posted September 8, 2008 Are you looking to do a one way databinding? i.e. just displaying information or also allowing updates to be sent back? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Nate Bross Posted September 8, 2008 Author Posted September 8, 2008 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. Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Nate Bross Posted September 11, 2008 Author Posted September 11, 2008 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. Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Administrators PlausiblyDamp Posted September 17, 2008 Administrators Posted September 17, 2008 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... Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Nate Bross Posted September 19, 2008 Author Posted September 19, 2008 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? Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Nate Bross Posted January 8, 2009 Author Posted January 8, 2009 Maybe this should be a new thread, but what is the difference between these Dependency Properties and using INotifyPropertyChanged? Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.