WPF custom control DependencyProperty won't databind?

It doesn't look like you have bound your Slider to your dependency property. Something like.

Up vote 1 down vote favorite share g+ share fb share tw.

I have a really simple user control called SetSpeed: It has a DependencyProperty called Speed: public partial class SetSpeed : UserControl { public SetSpeed() { InitializeComponent(); } public static readonly DependencyProperty SpeedProperty; static SetSpeed() { var md = new FrameworkPropertyMetadata(0.0); SetSpeed. SpeedProperty = DependencyProperty. Register( "Speed", typeof(double), typeof(SetSpeed), md); } public double Speed { get { return (double)GetValue(SetSpeed.

SpeedProperty); } set { SetValue(SetSpeed. SpeedProperty, value); } } } I have placed the control in a Window and am binding an element (any element) to it: Simple as it comes. No dice, though.

When I move the slider, the value in the TextBlock never changes. What am I missing, here? C# wpf xaml data-binding dependency-properties link|improve this question edited Apr 5 '11 at 19:48 asked Apr 5 '11 at 18:20Rap2,6721723 88% accept rate.

The slider and textbox bind to each other, yes, but as CodeNaked points out, you're never binding either of them to the custom dependency property. Therefore, in your Window, when you bind the TextBlock to Speed, it will never be updated. – SergioL Apr 5 '11 at 19:54 @Rap - What are you doing to change the Speed value then?

Because neither the Slider nor the TextBox in your UserControl above will change the Speed value. – CodeNaked Apr 5 '11 at 19:54 Oh, I see your point now. SergioL, thanks for pointing that out.

Once I added the binding, it worked great. Solved. – Rap Apr 5 '11 at 21:55 @Rap - Glad you got it working.

On a side note, it's probably better to bind the TextBox to directly to the UserControl's Speed property, than going through the Slider's Value property. – CodeNaked Apr 5 '11 at 22:18.

EDIT: Sorry, was looking at the slider property. :-) Try Setting your binding Mode to two way: Also, check your output console to see if there is a binding error. And set a breakpoint on your get method and see if it gets called.

Two-way bindings on TextBlocks are meaningless ;-), well as far as user input goes. – CodeNaked Apr 5 '11 at 18:28 It is a TextBox! Not a TextBlock.

– Erno Apr 5 '11 at 18:49 @Erno - You didn't see his/her unedited answer. – CodeNaked Apr 5 '11 at 18:57 Ah, so I missed the previous version... annoying when that happens ;) – Erno Apr 5 '11 at 19:11.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions