0

ウィンドウに一連の動的な計算フィールドを作成しようとしています。

現在、フォームが次のようにロードされたときに機能しています...

<Window.Resources>
    <src:PaymentVarianceConverter x:Key="PaymentConverter" />
</Window.Resources>

<TextBlock Text="{Binding Path=., Converter={StaticResource PaymentConverter}, 
                  ConverterParameter=CASH, StringFormat={}{0:C}, Mode=OneWay}"/>
<TextBlock Text="{Binding Path=., Converter={StaticResource PaymentConverter}, 
                  ConverterParameter=CHECK, StringFormat={}{0:C}, Mode=OneWay}"/>

ここにコンバータがあります:

public sealed class PaymentVarianceConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (!(value is Route))
            return null;
        var route = value as Route;

        switch (parameter.ToString())
        {
            case "CASH":
                return route.CashTotal - route.TotalExpectedCash;
            case "CHECK":
                return route.CheckTotal - route.TotalExpectedCheck;
            default:
                return null;
        }
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException("ConvertBack Not implemented");
    }
}

基になる値 (つまり、route.CashTotal) が変更されたときに更新されないことを除いて、これはすべてうまく機能します。

これを動的に更新する方法はありますか? ソースオブジェクトでそれらのプロパティを作成し、それらの多くがあるため、それぞれに対して OnPropertyChanged() を呼び出すことは避けたいと思います。

4

1 に答える 1

1

データ バインディングでは、バインドされた値が変更されたときに通知する必要があります。これを行うには、実装INotifiyPropertyChangedする必要があります。(または依存関係プロパティですが、それにはあなたに代わってより多くの作業が必要です。)残念ながら、WPFには超能力がありません。

于 2012-06-14T15:14:26.387 に答える