I have a custom "DateRangeSelector" control derived from ComboBox. This is a drop-down control with the following filters:
1. Today
2. Next three days
3. Next three weeks
4. Custom Range(Allows the user to set a custom date range)
Now this "DateRangeSelector" control is added to another XAML(ActivityListMenuControlView.xaml) as:
<DateRangeSelector:DateRangeSelectorControl x:Name="DateRangeSelector"
Grid.Column="1"
Margin="10 0 0 0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
AutomationProperties.AutomationId="AID_TaskListDateRangeSelector"
DateRangeUpdatedCmd="{Binding Path=DateRangeSelectionUpdatedCommand}"
TodayDateUpdatedCmd="{Binding Path=TodayDateUpdatedCommand}"
FontSize="{StaticResource TaskListMenuFontSize}"
RangeOptions="{Binding Path=DateRangeSelectionOptions,
Mode=OneTime}"
SelectedDateRange="{Binding Path=SelectedRange,
Mode=TwoWay}"
Visibility="{Binding Path=ShowFilterOptions,
Converter={StaticResource boolToVisibility}}" />
As evident from the code above i have created a command "TodayDateUpdatedCmd" in "DateRangeSelector" intended to update the "Today" filter in this control whenever the system date changes and binded to the command "TodayDateUpdatedCommand" in "ActivityListMenuControlViewModel".
Code to update the date is there in the method "SetDateValues" in "DateRangeSelector" itself.
I am just confused on how to excute this method from "ActivityListMenuControlViewModel"?
Please help.
UPDATE: DateRangeSelector is simply a class with no view/viewmodel. Here is the code:
public class DateRangeSelectorControl : ComboBox, INotifyPropertyChanged
{
public static readonly DependencyProperty TodayDateUpdateCmdProperty = DependencyProperty.Register("TodayDateUpdatedCmd", typeof(ICommand), typeof(DateRangeSelectorControl),
new PropertyMetadata(null));
public ICommand TodayDateUpdatedCmd
{
get { return (ICommand)this.GetValue(TodayDateUpdateCmdProperty); }
set
{
this.SetValue(TodayDateUpdateCmdProperty, value);
}
}
/// <summary>
///
/// </summary>
private void SetDateValues()
{
DateTime todaysDate = DateTime.Now;
TodayText = Utility.GetStringFromResource("TodayLabel") + " (" + todaysDate.ToShortDateString() + ")";
NextThreeDaysText = Utility.GetStringFromResource("NextThreeDaysLabel") + " (" + todaysDate.ToShortDateString() + " - " + todaysDate.AddDays(3).ToShortDateString() + ")";
NextWeekText = Utility.GetStringFromResource("NextWeekLabel") + " (" + todaysDate.ToShortDateString() + " - " + todaysDate.AddDays(7).ToShortDateString() + ")";
SetCustomDateRangeText();
}
}
As evident from the code above, i have first registered a dependency property "TodayDateUpdateCmdProperty" and the command property "TodayDateUpdatedCmd" which is used in "ActivityListMenuControlView.xaml" as seen in the XAML snippet. Further i need to execute the method "SetDateValues" in DateRangeSelector class to update the today date. Now please help me out how to achieve this?
UPDATE: As per the suggestions from @GazTheDestroyer i made the changes into the code and now not using any command.But now getting the runtime XamlParseException with the below details:
"'The invocation of the constructor on type 'VMS.Nexus.Client.Common.Controls.DateRangeSelector.DateRangeSelectorControl' that matches the specified binding constraints threw an exception.' Line number '45' and line position '14'."}
InnerException: {"Default value type does not match type of property 'TodayDate'."}
This exception is thrown in ActivityListMenuControlView.xaml where i created DateRangeSelector. Please help