WPF Binding to textbox not updating?

"YOU AND THE ART OF ONLINE DATING" is the only product on the market that will take you step-by-step through the process of online dating, provide you with the resources to help ensure success. Get it now!

Not sure if this is the issue, but you should pass "FPS" as the property name, not "FPSProperty", like so.

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

I have am writing a WPF application, and I have a textbox for the user to enter a frames per second value for video playback. The value of this textbox is bound to a dependency property in the code behind (trying to follow MVVM like a good designer). My problem is that the textbox is not updating automatically when the FPS value is changed externally.

For example, the user can control the value using a slider. The dependency properties value is changed correctly by the slider, but the textboxes text never updates, unless, of course, I do it manualy using GetBindingExpression(..).UpdateTarget() which is what I have implemented pending a better solution. Does anyone know if this is intended functionality or am I setting something up wrong?

Thanks, Max TextBox tag in XAML: Code behind for dependency property: #region public dependency property int FPS public static readonly DependencyProperty FPSProperty = DependencyProperty. Register("FPSProperty", typeof(int), typeof(GlobalSettings), new PropertyMetadata(MainWindow.appState.gSettings. Fps,FPSChanged,FPSCoerce), FPSValidate); public int FPS { get { return (int)GetValue(FPSProperty); } set { SetValue(FPSProperty, value); } } private static bool FPSValidate(object value) { return true; } private static object FPSCoerce(DependencyObject obj, object o) { return o; } private static void FPSChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) { //why do I need to update the binding manually?

Isnt that the point of a binding? // (obj as GlobalSettings).tbFPS. GetBindingExpression(TextBox.

TextProperty).UpdateTarget(); } #endregion c# wpf textbox binding dependency-properties link|improve this question asked Jun 24 '11 at 17:38Max Ehrlich15819 100% accept rate.

Not sure if this is the issue, but you should pass "FPS" as the property name, not "FPSProperty", like so: public static readonly DependencyProperty FPSProperty = DependencyProperty. Register("FPS", typeof(int), typeof(GlobalSettings), new PropertyMetadata(MainWindow.appState.gSettings. Fps,FPSChanged,FPSCoerce), FPSValidate).

Yup that was it, thanks for your genius – Max Ehrlich Jun 24 '11 at 17:56.

I also think you need to add the FrameworkPropertyMetadataOptions. BindsToWayByDefault to your dependency property registration otherwise you need to manually set the mode on your TextBox. Text binding to TwoWay.

To use the FrameworkPropertyMetadataOptions, you need to use FrameworkPropertyMetaData instead of PropertyMetadata in your registration: public static readonly DependencyProperty FPSProperty = DependencyProperty. Register("FPS", typeof(int), typeof(GlobalSettings), new FrameworkPropertyMetadata(MainWindow.appState.gSettings. Fps, FrameworkPropertyMetadataOptions.

BindsTwoWayByDefault, FPSChanged, FPSCoerce), FPSValidate).

Well it seems like its working fine after I implemented the suggestion by @CodeNaked I thought two way binding was the default anyway – Max Ehrlich Jun 24 '11 at 18:08 If it's working, great. I just know that I've run into problems before where the option was not specified in the registration and my binding failed unless I set the mode explicitly. Maybe this is a change in 4.0?

– crazyarabian Jun 24 '11 at 18:16.

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