1

これに対する答えを見たときに「当然」と言うだろうと確信していますが、私の心は現在望んでいるほどパフォーマンスが高くないので、ここで非同期ヘルプスレッドをスピンアップして支援しています...

次のクラスを想定します。

public class DerivedTicket: Ticket
{
    public ObservableCollection<TicketDetail> TicketDetails { get; set; }
}

public class Ticket
{
    public static readonly DependencyProperty SubTotalProperty = DependencyProperty.Register("SubTotal", typeof(decimal), typeof(TicketsRow));
    public static readonly DependencyProperty TaxProperty = DependencyProperty.Register("Tax", typeof(decimal), typeof(TicketsRow));
    public static readonly DependencyProperty TotalProperty = DependencyProperty.Register("Total", typeof(decimal), typeof(TicketsRow));

    public decimal SubTotal
    {
        get { return (decimal)this.GetValue(SubTotalProperty); }
        set { this.SetValue(SubTotalProperty, value); }
    }

    public decimal Tax
    {
        get { return (decimal)this.GetValue(TaxProperty); }
        set { this.SetValue(TaxProperty, value); }
    }

    public decimal Total
    {
        get { return (decimal)this.GetValue(TotalProperty); }
        set { this.SetValue(TotalProperty, value); }
    }
}


public class TicketDetail
{
    public static readonly DependencyProperty ItemIdProperty = DependencyProperty.Register("ItemId", typeof(int?), typeof(TicketDetailsRow));
    public static readonly DependencyProperty PriceProperty = DependencyProperty.Register("Price", typeof(decimal), typeof(TicketDetailsRow));
    public static readonly DependencyProperty TaxProperty = DependencyProperty.Register("Tax", typeof(decimal?), typeof(TicketDetailsRow));
    public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register("Description", typeof(string), typeof(TicketDetailsRow));

    public int? ItemId
    {
        get { return (int?)this.GetValue(ItemIdProperty); }
        set { this.SetValue(ItemIdProperty, value); }
    }

    [Field]
    public decimal Price
    {
        get { return (decimal)this.GetValue(PriceProperty); }
        set { this.SetValue(PriceProperty, value); }
    }

    [Field]
    public decimal? Tax
    {
        get { return (decimal?)this.GetValue(TaxProperty); }
        set { this.SetValue(TaxProperty, value); }
    }

    [Field]
    public string Description
    {
        get { return (string)this.GetValue(DescriptionProperty); }
        set { this.SetValue(DescriptionProperty, value); }
    }
}

SubTotalを の合計とどのように同期させTicketDetailsますか? バインディングを使用するかINotifyPropertyChanged、または他の方法を使用しますか?

4

1 に答える 1

3

のイベントNotifyCollectionChangedを使用してObservableCollection、チケットの詳細の変更について通知を受け、依存関係プロパティを再計算できますSubTotal

于 2013-01-14T08:53:04.330 に答える