私はWPFアプリケーションを作成していますが、ビデオ再生のために1秒あたりのフレーム数を入力するためのテキストボックスがあります。このテキストボックスの値は、コードビハインドの依存関係プロパティにバインドされています(優れたデザイナーのようにMVVMをフォローしようとしています)。私の問題は、FPS値が外部で変更されたときにテキストボックスが自動的に更新されないということです。たとえば、スライダを使用して値を制御できます。依存関係プロパティの値はスライダによって正しく変更されますが、テキストボックスのテキストは決して更新されません。もちろん、GetBindingExpression(..)を使用して手動で行う必要はありません。UpdateTarget()誰かがこれが意図された機能であるかどうかを知っていますか? XAMLでWPFテキストボックスへのバインディングの更新がありません
おかげで、 マックス
のTextBoxタグ:依存関係プロパティの背後
<TextBox Text="{Binding FPS}" Name="tbFPS" FlowDirection="RightToLeft"/>
コード:「これは問題ですが、あなたが渡すべきかどう
#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
うん、あなたの天才 –