Firstly I am assuming DependencyProperty is what to use but I could be wrong - Maybe a INotifyPropertyChanged is more suitable?
I have a few UI controls that are all associated to audio playback. I would like to bind the Volume and Track Seek Sliders to a couple of doubles.
- The volume slider will update the audio classes Volume variable when the Value is updated
- The Track Seeking slider MaxValue will be set to the duration of the track in milliseconds and will upda开发者_如何学Cte the seeking position variable of my audio playback class
New to Dependency properties and such so you help is much appreciated!
You don't need dependency properties for that, simply implement INotifyPropertyChanged
so the binding engine is aware of changes to your property.
DependencyProperties are for sparse data-structures like Controls which have a huge amount of properties of which only a few are set, this saves memory. If you bind to your own data DPs normally do not make that much sense because your properties will be set and you might want to access your data-object from different threads which is not easily possible with DependencyObjects.
Also see this question which compares the two in regards to using them in a ViewModel.
精彩评论