MainViewModel is instantiated then:
clicking on the Daily-Button instantiates the:
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
}
After the DateNavigatorViewModel got instantiated see BELOW
clicking on the Weekly-Button instantiates the:
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
}
After the DateNavigatorViewModel got instantiated see BELOW
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...
}
Now the property that got fired setting the DateTime.Now in the Ctor
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,
}
}
The infoObject is send both to the Daily and WeeklyViewModel but depending on the DateNavigatorMode the database fetching is rejected from the ViewModel.
For me thats a solution because it firstly works and second no DAL is involved just the ViewModels.
Someone might mark it as solution if you like it. Critics are welcome too maybe I can still improve something?