Displaying dates as holiday in WPF Calendar
up vote
0
down vote
favorite
I'm using WPF Calendar control to add Holidays. User can select days and the selected days will be inserted to a database table as holiday.
After the insertion, I'm displaying the days in Holiday table as BlackoutDates
in the calendar as in the following code.
XAML
<Calendar x:Name="HolidayCalendar" SelectedDatesChanged="Calendar_SelectionChanged"
SelectionMode="MultipleRange" Loaded="Calendar_Loaded">
C#
DateTime now = DateTime.Now;
var startDate = new DateTime(now.Year, now.Month, 1);
var endDate = startDate.AddMonths(1).AddDays(-1);
GetHolidayService getHolidayService = new GetHolidayService();
ObservableCollection<GetHoliday> GetHolidayBaseList = new ObservableCollection<GetHoliday>();
PostHoliday postHoliday = new PostHoliday();
postHoliday.StartDate = startDate;
postHoliday.EndDate = endDate;
GetHolidayBaseList = getHolidayService.GetHolidayServiceFunction(postHoliday);
foreach (var item in GetHolidayList)
{
HolidayCalendar.BlackoutDates.Add(new CalendarDateRange(item.HolidayDate,item.HolidayDate)) ;
}
Current output
I want to achieve something like this - Holidays marked as Red
as in this link
Any help to write a control template required for this functionality is appreciated.
Thanks in advance!
c# wpf wpf-controls
add a comment |
up vote
0
down vote
favorite
I'm using WPF Calendar control to add Holidays. User can select days and the selected days will be inserted to a database table as holiday.
After the insertion, I'm displaying the days in Holiday table as BlackoutDates
in the calendar as in the following code.
XAML
<Calendar x:Name="HolidayCalendar" SelectedDatesChanged="Calendar_SelectionChanged"
SelectionMode="MultipleRange" Loaded="Calendar_Loaded">
C#
DateTime now = DateTime.Now;
var startDate = new DateTime(now.Year, now.Month, 1);
var endDate = startDate.AddMonths(1).AddDays(-1);
GetHolidayService getHolidayService = new GetHolidayService();
ObservableCollection<GetHoliday> GetHolidayBaseList = new ObservableCollection<GetHoliday>();
PostHoliday postHoliday = new PostHoliday();
postHoliday.StartDate = startDate;
postHoliday.EndDate = endDate;
GetHolidayBaseList = getHolidayService.GetHolidayServiceFunction(postHoliday);
foreach (var item in GetHolidayList)
{
HolidayCalendar.BlackoutDates.Add(new CalendarDateRange(item.HolidayDate,item.HolidayDate)) ;
}
Current output
I want to achieve something like this - Holidays marked as Red
as in this link
Any help to write a control template required for this functionality is appreciated.
Thanks in advance!
c# wpf wpf-controls
Hey, I've edited my question. Will you please refer it again? Is my question clear now?
– George T Kurian
12 hours ago
I want to display Holidays as different, something like I mentioned in the picture (holidays marked as red). If I'm adding holidays to SelectedDates, if my user selects some new date, user can't differentiate SelectedDates from Holidays. That's why. Is it clear now?
– George T Kurian
12 hours ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm using WPF Calendar control to add Holidays. User can select days and the selected days will be inserted to a database table as holiday.
After the insertion, I'm displaying the days in Holiday table as BlackoutDates
in the calendar as in the following code.
XAML
<Calendar x:Name="HolidayCalendar" SelectedDatesChanged="Calendar_SelectionChanged"
SelectionMode="MultipleRange" Loaded="Calendar_Loaded">
C#
DateTime now = DateTime.Now;
var startDate = new DateTime(now.Year, now.Month, 1);
var endDate = startDate.AddMonths(1).AddDays(-1);
GetHolidayService getHolidayService = new GetHolidayService();
ObservableCollection<GetHoliday> GetHolidayBaseList = new ObservableCollection<GetHoliday>();
PostHoliday postHoliday = new PostHoliday();
postHoliday.StartDate = startDate;
postHoliday.EndDate = endDate;
GetHolidayBaseList = getHolidayService.GetHolidayServiceFunction(postHoliday);
foreach (var item in GetHolidayList)
{
HolidayCalendar.BlackoutDates.Add(new CalendarDateRange(item.HolidayDate,item.HolidayDate)) ;
}
Current output
I want to achieve something like this - Holidays marked as Red
as in this link
Any help to write a control template required for this functionality is appreciated.
Thanks in advance!
c# wpf wpf-controls
I'm using WPF Calendar control to add Holidays. User can select days and the selected days will be inserted to a database table as holiday.
After the insertion, I'm displaying the days in Holiday table as BlackoutDates
in the calendar as in the following code.
XAML
<Calendar x:Name="HolidayCalendar" SelectedDatesChanged="Calendar_SelectionChanged"
SelectionMode="MultipleRange" Loaded="Calendar_Loaded">
C#
DateTime now = DateTime.Now;
var startDate = new DateTime(now.Year, now.Month, 1);
var endDate = startDate.AddMonths(1).AddDays(-1);
GetHolidayService getHolidayService = new GetHolidayService();
ObservableCollection<GetHoliday> GetHolidayBaseList = new ObservableCollection<GetHoliday>();
PostHoliday postHoliday = new PostHoliday();
postHoliday.StartDate = startDate;
postHoliday.EndDate = endDate;
GetHolidayBaseList = getHolidayService.GetHolidayServiceFunction(postHoliday);
foreach (var item in GetHolidayList)
{
HolidayCalendar.BlackoutDates.Add(new CalendarDateRange(item.HolidayDate,item.HolidayDate)) ;
}
Current output
I want to achieve something like this - Holidays marked as Red
as in this link
Any help to write a control template required for this functionality is appreciated.
Thanks in advance!
c# wpf wpf-controls
c# wpf wpf-controls
edited 12 hours ago
asked 19 hours ago
George T Kurian
187
187
Hey, I've edited my question. Will you please refer it again? Is my question clear now?
– George T Kurian
12 hours ago
I want to display Holidays as different, something like I mentioned in the picture (holidays marked as red). If I'm adding holidays to SelectedDates, if my user selects some new date, user can't differentiate SelectedDates from Holidays. That's why. Is it clear now?
– George T Kurian
12 hours ago
add a comment |
Hey, I've edited my question. Will you please refer it again? Is my question clear now?
– George T Kurian
12 hours ago
I want to display Holidays as different, something like I mentioned in the picture (holidays marked as red). If I'm adding holidays to SelectedDates, if my user selects some new date, user can't differentiate SelectedDates from Holidays. That's why. Is it clear now?
– George T Kurian
12 hours ago
Hey, I've edited my question. Will you please refer it again? Is my question clear now?
– George T Kurian
12 hours ago
Hey, I've edited my question. Will you please refer it again? Is my question clear now?
– George T Kurian
12 hours ago
I want to display Holidays as different, something like I mentioned in the picture (holidays marked as red). If I'm adding holidays to SelectedDates, if my user selects some new date, user can't differentiate SelectedDates from Holidays. That's why. Is it clear now?
– George T Kurian
12 hours ago
I want to display Holidays as different, something like I mentioned in the picture (holidays marked as red). If I'm adding holidays to SelectedDates, if my user selects some new date, user can't differentiate SelectedDates from Holidays. That's why. Is it clear now?
– George T Kurian
12 hours ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
This is how you can do it,
First define custom style for CalendarDataButton based on standard style
<Calendar x:Name="HolidayCalendar" SelectionMode="MultipleRange">
<Calendar.CalendarDayButtonStyle>
<Style TargetType="CalendarDayButton" BasedOn="{StaticResource {x:Type CalendarDayButton}}">
<Style.Triggers>
<Trigger Property="IsBlackedOut" Value="True">
<Setter Property="Background" Value="DeepPink"/>
<Setter Property="local:CalenderHelper.IsBlackOutDisabled" Value="True"/>
</Trigger>
</Style.Triggers>
</Style>
</Calendar.CalendarDayButtonStyle>
<Calendar.BlackoutDates>
<CalendarDateRange Start="21-Nov-2018" End="21-Nov-2018"/>
<CalendarDateRange Start="25-Nov-2018" End="25-Nov-2018"/>
</Calendar.BlackoutDates>
</Calendar>
In order to remove the strike mark from Blackout date, you will have to use the below attached property 'IsBlackOutDisabled'
public class CalenderHelper : DependencyObject
{
public static readonly DependencyProperty IsBlackOutDisabledProperty =
DependencyProperty.RegisterAttached("IsBlackOutDisabled", typeof(bool), typeof(CalenderHelper), new PropertyMetadata(false, OnIsBlackOutDisabledChanged));
public static bool GetIsBlackOutDisabled(DependencyObject obj)
{
return (bool)obj.GetValue(IsBlackOutDisabledProperty);
}
public static void SetIsBlackOutDisabled(DependencyObject obj, bool value)
{
obj.SetValue(IsBlackOutDisabledProperty, value);
}
private static void OnIsBlackOutDisabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
CalendarDayButton dayButton = d as CalendarDayButton;
if (dayButton.IsLoaded)
{
SetBlackout(dayButton, (bool)e.NewValue);
}
else
{
dayButton.Loaded += (s, ee) =>
{
SetBlackout(dayButton, (bool)e.NewValue);
};
}
}
static void SetBlackout(CalendarDayButton dayButton, bool collapsed)
{
ControlTemplate template = dayButton.Template;
Path blackoutPath = template.FindName("Blackout", dayButton) as Path;
if (collapsed)
blackoutPath.Visibility = System.Windows.Visibility.Collapsed;
else
blackoutPath.Visibility = System.Windows.Visibility.Visible;
}
}
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
This is how you can do it,
First define custom style for CalendarDataButton based on standard style
<Calendar x:Name="HolidayCalendar" SelectionMode="MultipleRange">
<Calendar.CalendarDayButtonStyle>
<Style TargetType="CalendarDayButton" BasedOn="{StaticResource {x:Type CalendarDayButton}}">
<Style.Triggers>
<Trigger Property="IsBlackedOut" Value="True">
<Setter Property="Background" Value="DeepPink"/>
<Setter Property="local:CalenderHelper.IsBlackOutDisabled" Value="True"/>
</Trigger>
</Style.Triggers>
</Style>
</Calendar.CalendarDayButtonStyle>
<Calendar.BlackoutDates>
<CalendarDateRange Start="21-Nov-2018" End="21-Nov-2018"/>
<CalendarDateRange Start="25-Nov-2018" End="25-Nov-2018"/>
</Calendar.BlackoutDates>
</Calendar>
In order to remove the strike mark from Blackout date, you will have to use the below attached property 'IsBlackOutDisabled'
public class CalenderHelper : DependencyObject
{
public static readonly DependencyProperty IsBlackOutDisabledProperty =
DependencyProperty.RegisterAttached("IsBlackOutDisabled", typeof(bool), typeof(CalenderHelper), new PropertyMetadata(false, OnIsBlackOutDisabledChanged));
public static bool GetIsBlackOutDisabled(DependencyObject obj)
{
return (bool)obj.GetValue(IsBlackOutDisabledProperty);
}
public static void SetIsBlackOutDisabled(DependencyObject obj, bool value)
{
obj.SetValue(IsBlackOutDisabledProperty, value);
}
private static void OnIsBlackOutDisabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
CalendarDayButton dayButton = d as CalendarDayButton;
if (dayButton.IsLoaded)
{
SetBlackout(dayButton, (bool)e.NewValue);
}
else
{
dayButton.Loaded += (s, ee) =>
{
SetBlackout(dayButton, (bool)e.NewValue);
};
}
}
static void SetBlackout(CalendarDayButton dayButton, bool collapsed)
{
ControlTemplate template = dayButton.Template;
Path blackoutPath = template.FindName("Blackout", dayButton) as Path;
if (collapsed)
blackoutPath.Visibility = System.Windows.Visibility.Collapsed;
else
blackoutPath.Visibility = System.Windows.Visibility.Visible;
}
}
add a comment |
up vote
0
down vote
This is how you can do it,
First define custom style for CalendarDataButton based on standard style
<Calendar x:Name="HolidayCalendar" SelectionMode="MultipleRange">
<Calendar.CalendarDayButtonStyle>
<Style TargetType="CalendarDayButton" BasedOn="{StaticResource {x:Type CalendarDayButton}}">
<Style.Triggers>
<Trigger Property="IsBlackedOut" Value="True">
<Setter Property="Background" Value="DeepPink"/>
<Setter Property="local:CalenderHelper.IsBlackOutDisabled" Value="True"/>
</Trigger>
</Style.Triggers>
</Style>
</Calendar.CalendarDayButtonStyle>
<Calendar.BlackoutDates>
<CalendarDateRange Start="21-Nov-2018" End="21-Nov-2018"/>
<CalendarDateRange Start="25-Nov-2018" End="25-Nov-2018"/>
</Calendar.BlackoutDates>
</Calendar>
In order to remove the strike mark from Blackout date, you will have to use the below attached property 'IsBlackOutDisabled'
public class CalenderHelper : DependencyObject
{
public static readonly DependencyProperty IsBlackOutDisabledProperty =
DependencyProperty.RegisterAttached("IsBlackOutDisabled", typeof(bool), typeof(CalenderHelper), new PropertyMetadata(false, OnIsBlackOutDisabledChanged));
public static bool GetIsBlackOutDisabled(DependencyObject obj)
{
return (bool)obj.GetValue(IsBlackOutDisabledProperty);
}
public static void SetIsBlackOutDisabled(DependencyObject obj, bool value)
{
obj.SetValue(IsBlackOutDisabledProperty, value);
}
private static void OnIsBlackOutDisabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
CalendarDayButton dayButton = d as CalendarDayButton;
if (dayButton.IsLoaded)
{
SetBlackout(dayButton, (bool)e.NewValue);
}
else
{
dayButton.Loaded += (s, ee) =>
{
SetBlackout(dayButton, (bool)e.NewValue);
};
}
}
static void SetBlackout(CalendarDayButton dayButton, bool collapsed)
{
ControlTemplate template = dayButton.Template;
Path blackoutPath = template.FindName("Blackout", dayButton) as Path;
if (collapsed)
blackoutPath.Visibility = System.Windows.Visibility.Collapsed;
else
blackoutPath.Visibility = System.Windows.Visibility.Visible;
}
}
add a comment |
up vote
0
down vote
up vote
0
down vote
This is how you can do it,
First define custom style for CalendarDataButton based on standard style
<Calendar x:Name="HolidayCalendar" SelectionMode="MultipleRange">
<Calendar.CalendarDayButtonStyle>
<Style TargetType="CalendarDayButton" BasedOn="{StaticResource {x:Type CalendarDayButton}}">
<Style.Triggers>
<Trigger Property="IsBlackedOut" Value="True">
<Setter Property="Background" Value="DeepPink"/>
<Setter Property="local:CalenderHelper.IsBlackOutDisabled" Value="True"/>
</Trigger>
</Style.Triggers>
</Style>
</Calendar.CalendarDayButtonStyle>
<Calendar.BlackoutDates>
<CalendarDateRange Start="21-Nov-2018" End="21-Nov-2018"/>
<CalendarDateRange Start="25-Nov-2018" End="25-Nov-2018"/>
</Calendar.BlackoutDates>
</Calendar>
In order to remove the strike mark from Blackout date, you will have to use the below attached property 'IsBlackOutDisabled'
public class CalenderHelper : DependencyObject
{
public static readonly DependencyProperty IsBlackOutDisabledProperty =
DependencyProperty.RegisterAttached("IsBlackOutDisabled", typeof(bool), typeof(CalenderHelper), new PropertyMetadata(false, OnIsBlackOutDisabledChanged));
public static bool GetIsBlackOutDisabled(DependencyObject obj)
{
return (bool)obj.GetValue(IsBlackOutDisabledProperty);
}
public static void SetIsBlackOutDisabled(DependencyObject obj, bool value)
{
obj.SetValue(IsBlackOutDisabledProperty, value);
}
private static void OnIsBlackOutDisabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
CalendarDayButton dayButton = d as CalendarDayButton;
if (dayButton.IsLoaded)
{
SetBlackout(dayButton, (bool)e.NewValue);
}
else
{
dayButton.Loaded += (s, ee) =>
{
SetBlackout(dayButton, (bool)e.NewValue);
};
}
}
static void SetBlackout(CalendarDayButton dayButton, bool collapsed)
{
ControlTemplate template = dayButton.Template;
Path blackoutPath = template.FindName("Blackout", dayButton) as Path;
if (collapsed)
blackoutPath.Visibility = System.Windows.Visibility.Collapsed;
else
blackoutPath.Visibility = System.Windows.Visibility.Visible;
}
}
This is how you can do it,
First define custom style for CalendarDataButton based on standard style
<Calendar x:Name="HolidayCalendar" SelectionMode="MultipleRange">
<Calendar.CalendarDayButtonStyle>
<Style TargetType="CalendarDayButton" BasedOn="{StaticResource {x:Type CalendarDayButton}}">
<Style.Triggers>
<Trigger Property="IsBlackedOut" Value="True">
<Setter Property="Background" Value="DeepPink"/>
<Setter Property="local:CalenderHelper.IsBlackOutDisabled" Value="True"/>
</Trigger>
</Style.Triggers>
</Style>
</Calendar.CalendarDayButtonStyle>
<Calendar.BlackoutDates>
<CalendarDateRange Start="21-Nov-2018" End="21-Nov-2018"/>
<CalendarDateRange Start="25-Nov-2018" End="25-Nov-2018"/>
</Calendar.BlackoutDates>
</Calendar>
In order to remove the strike mark from Blackout date, you will have to use the below attached property 'IsBlackOutDisabled'
public class CalenderHelper : DependencyObject
{
public static readonly DependencyProperty IsBlackOutDisabledProperty =
DependencyProperty.RegisterAttached("IsBlackOutDisabled", typeof(bool), typeof(CalenderHelper), new PropertyMetadata(false, OnIsBlackOutDisabledChanged));
public static bool GetIsBlackOutDisabled(DependencyObject obj)
{
return (bool)obj.GetValue(IsBlackOutDisabledProperty);
}
public static void SetIsBlackOutDisabled(DependencyObject obj, bool value)
{
obj.SetValue(IsBlackOutDisabledProperty, value);
}
private static void OnIsBlackOutDisabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
CalendarDayButton dayButton = d as CalendarDayButton;
if (dayButton.IsLoaded)
{
SetBlackout(dayButton, (bool)e.NewValue);
}
else
{
dayButton.Loaded += (s, ee) =>
{
SetBlackout(dayButton, (bool)e.NewValue);
};
}
}
static void SetBlackout(CalendarDayButton dayButton, bool collapsed)
{
ControlTemplate template = dayButton.Template;
Path blackoutPath = template.FindName("Blackout", dayButton) as Path;
if (collapsed)
blackoutPath.Visibility = System.Windows.Visibility.Collapsed;
else
blackoutPath.Visibility = System.Windows.Visibility.Visible;
}
}
answered 9 hours ago
RajN
3,3432921
3,3432921
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371091%2fdisplaying-dates-as-holiday-in-wpf-calendar%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Hey, I've edited my question. Will you please refer it again? Is my question clear now?
– George T Kurian
12 hours ago
I want to display Holidays as different, something like I mentioned in the picture (holidays marked as red). If I'm adding holidays to SelectedDates, if my user selects some new date, user can't differentiate SelectedDates from Holidays. That's why. Is it clear now?
– George T Kurian
12 hours ago