2016-09-21 146 views
0

我有一個WPF-UI與兩個日期選擇器。第一個日期選擇器設置當前日期,第二個日期選擇器設置參考日期。根據datepickers中選擇的這兩個日期將數據加載到網格中,並顯示它們隨時間的變化。與INotifyPropertyChanged相互依賴的屬性

我現在的問題是,選擇當前日期當然應該以這樣的方式影響參考日期,即噹噹前日期落後於參考日期時,參考日期應該被自動設置爲落後一天選定的日期。例如:

CurrentDate = new Datetime(2016,09,12); // Selected to be the 12th 
if(ReferenceDate > CurrentDate) 
    ReferenceDate = CurrentDate.AddDays(-1) 

無論何時日期發生變化,數據現在都會重新加載到datagrid中。在這種情況下,這意味着我必須在選擇當前日期時重新​​加載數據,但是當選擇參考日期時,我還必須重新加載數據。應用上面的方法會導致調用loadData方法兩次。

propertyChanged(parameters...) { 
    if(CurrentDate) 
     loadData(); // Selecting the CurrentDate will load Data 
    if(ReferenceDate) 
     loadData(); // Automatically changing the RefDate will load the data a second time 
} 

(代碼片段只是爲了說明問題,他們不是實際的代碼)

我會爲如何實現一種機制,允許只提出一個通知,一旦您的任何想法感謝整個日期選擇操作。

回答

0

最好選擇DP over INPC。 DP允許Coercion, and Validation。 但是如果你想使用INPC,你可以在CurDate的setter中更改RefDate,並且從CurrentDate自己提升OnPropertyChanged("ReferenceDate")

+0

我認爲DependecyProperties應該只用於當我想通過UI訪問一個自定義的屬性。 – narain

+0

@narain DP下降是必須在DO中定義的。 – AnjumSKhan