MainViewModel被實例化,則:在日用按鈕
點擊實例化:
public DailyViewModel(IMessenger messenger)
{
_messenger = messenger;
_messenger.Register<DateNavigatorInfoObject>(this, LoadDailyData);
}
private void LoadDailyData(DateNavigatorInfoObject infoObject)
{
if (infoObject.DateNavigatorMode != DateTest.DateMode.Day)
return;
// get daily database stuff
}
後DateNavigatorViewModel得到實例看低於
點擊每週按鈕 instantiat ES的:
public WeeklyViewModel(IMessenger messenger)
{
_messenger = messenger;
_messenger.Register<DateNavigatorInfoObject>(this, LoadWeeklyData);
}
private void LoadWeeklyData(DateNavigatorInfoObject infoObject)
{
if (infoObject.DateNavigatorMode != DateTest.DateMode.Week)
return;
// get weekly database stuff
}
後DateNavigatorViewModel得到實例看低於
public DateNavigatorViewModel(IMainRepository mainRepo, IMessenger messenger)
{
_mainRepo = mainRepo;
_messenger = messenger;
SelectedDate = DateTime.Now;
// Wether daily/weekly data is fetched the start date for the data is NOW // when the ViewModels are instantiated the first time using a ViewModelLocator...
}
現在被解僱了在構造函數
private DateTime _selectedDate;
public DateTime SelectedDate
{
get { return _selectedDate; }
set
{
if (_selectedDate.Date == value.Date)
return;
_selectedDate = value;
this.RaisePropertyChanged("SelectedDate");
var infoObject = new DateNavigatorInfoObject();
switch (DateNavigatorMode)
{
case DateTest.DateMode.Day:
infoObject.DateNavigatorMode = DateNavigatorMode;
infoObject.SelectedStartDate = value;
break;
case DateTest.DateMode.Week:
infoObject.DateNavigatorMode = DateNavigatorMode;
infoObject.SelectedStartDate = value;
infoObject.SelectedEndDate = value.AddDays(6);
break;
}
_messenger.Send(infoObject);
}
public class DateTest
{
public enum DateMode
{
Day,
Week,
Month,
}
}
的設置DateTime.Now屬性infoObject發送給Daily和WeeklyViewModel,但取決於DateNavigatorMode數據庫抓取從ViewModel中被拒絕。
對我來說這是一個解決方案,因爲它第一次工作,第二沒有DAL只涉及ViewModels。
有人可能會標記爲解決方案,如果你喜歡它。批評者也歡迎,也許我仍然可以改進一些東西?
你如何不讓我猜? – devuxer 2010-10-24 20:47:52
你是什麼意思?所有信息都張貼在上面?啊......你看不到我看到的最後一句話。 DateTime的值發送給兩個ViewModels,所以我得到的數據兩次......不是很酷嗎? – Elisabeth 2010-10-24 20:55:25