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:
<TextBox Text="{Binding FPS}" Name="tbFPS" FlowDirection="RightToLeft"/>
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