2016-08-12 31 views
1

このコードには、XAMLバインディングのプロパティ変更イベントを発生させるインデクサーと、私たちのフレームワークのイベントがあります。インデクサーのRaiseプロパティが変更されていません

インデクサーでいくつかのXAMLコントロールをバインドしましたが、インターフェイスを初期化するときにバインディングが原因でget内でブレークします。しかし、コントロールの値を変更すると、OnSomeBusinessCurrentEntityPropertyChangedメソッドでブレークし、ifという条件を入力し、インデクサー名でOnPropertyChangedイベントを呼び出します。しかし、インターフェースは決して更新されません。

私はこのコードを書いたときにUIがうまくいっていたのですが、TotalDailyTotalにリネームした後、動作を停止しました。誰かがIndexerがリフレッシュされない理由の手がかりを持っていますか?

ここで結合と私のXAMLコントロールのexempleです:

<max:MaxLabel x:Name="tbnTotalHour1" max:CustomBindingBehavior.IsCustomBindingIgnored="True" Content="{Binding Path=[0], Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" /> 

コード:

protected override void OnSomeBusinessCurrentEntityPropertyChanged(object sender, PropertyChangedEventArgs e) 
{ 
    base.OnSomeBusinessCurrentEntityPropertyChanged(sender, e); 
    if (sender is TimeSheet) 
     this.OnPropertyChanged("Total[]") 
} 

[IndexerName("Total")] 
public long this[int dateModifier] 
{ 
    get 
    { 
     var date = this.WorkingEntity.PayrollPeriodStartDate.AddDays(dateModifier); 
     TimeSpan total = TimeSpan.Zero; 
     foreach (var view in this.CurrentWorkingTimesheetByActivity.ViewList) 
     { 
       var detail = view.Details[date]; 
       if (detail != null) 
        total += detail.TimeSheet.Duration; 
     } 
     return total.Ticks; 
    } 
} 
+0

なしインデクサ名を使用し、私は人々が与えることなくdownvoteどのように好き私の質問はかなり合法だと思います。 –

+0

有益かつ明確な質問のために上書きされました。 – jonathana

答えて

1

結合システムは定数で定義された "アイテム[]" という名前のプロパティ、探しているが、文字列Binding.IndexerName。ちょうどあなたのコード更新

if (PropertyChanged != null) 
{ 
    PropertyChanged(this, new PropertyChangedEventArgs(Binding.IndexerName)); 
} 

:あなた自身のセッターでは、通知は次のようになり、カスタムインデクサ名を使用する場合は

protected override void OnSomeBusinessCurrentEntityPropertyChanged(object  sender, PropertyChangedEventArgs e) 
{ 
    base.OnSomeBusinessCurrentEntityPropertyChanged(sender, e); 
    if (sender is TimeSheet) 
     this.OnPropertyChanged(Binding.IndexerName) 
} 

EDIT

を、I多くの推測の後に私の自己によってこの方法を設立しました:

属性をIndexerName属性で飾る。

変更XAMLは、あなたのインデクサ名でバインド:

<max:MaxLabel x:Name="tbnTotalHour1" max:CustomBindingBehavior.IsCustomBindingIgnored="True" Content="{Binding Path=Total[0], Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" /> 

や変更の調達でちょうど「[]」

protected override void OnSomeBusinessCurrentEntityPropertyChanged(object sender, PropertyChangedEventArgs e) 
{ 
    base.OnSomeBusinessCurrentEntityPropertyChanged(sender, e); 
    if (sender is TimeSheet) 
     this.OnPropertyChanged("Total") 
} 
+0

インデクサーの上のIndexerNameを削除した後で動作します。なぜItem []はうまくいったのですか? –

+0

'Binding.IndexerName'を使うのが好きです。 –

+0

ええ、なぜ' Item [] 'が働いているのですか(' Binding.IndexerName'は単なる定数なので)。私のIndexerNameが 'Total'であると言う属性を持つ' Total [] 'はありませんでしたか?私は知りたいと思っています。 –

関連する問題