接上篇wpf日历控件制作过程分析(1) 定义header
在header中,我们看到了定义一个自定义样式TitleStyle
1.自定义样式
看后台代码定义
Code
/**//// <summary>
/// The DependencyProperty for the TitleStyle property.
/// Flags: none
/// Default Value: null
/// </summary>
public static readonly DependencyProperty TitleStyleProperty =
DependencyProperty.Register(
"TitleStyle",
typeof(Style),
typeof(MonthCalendar),
new FrameworkPropertyMetadata(
(Style)null));
/**//// <summary>
/// TitleStyle property
/// </summary>
public Style TitleStyle
{
get { return (Style)GetValue(TitleStyleProperty); }
set { SetValue(TitleStyleProperty, value); }
}
应该说,是比较简单的,默认样式为null,如果指定了样式的话,则会覆盖默认的样式
2.不重叠选择样式
为日历的前进和后退按钮定义两个样式
Code
/**//// <summary>
/// The DependencyProperty for the PreviousButtonStyle property.
/// Flags: none
/// Default Value: null
/// </summary>
public static readonly DependencyProperty PreviousButtonStyleProperty =
DependencyProperty.Register(
"PreviousButtonStyle",
typeof(Style),
typeof(MonthCalendar),
new FrameworkPropertyMetadata(
(Style)null, new PropertyChangedCallback(OnPreviousButtonStyleChanged)));
/**//// <summary>
/// PreviousButtonStyle property
/// </summary>
public Style PreviousButtonStyle
{
get { return (Style)GetValue(PreviousButtonStyleProperty); }
set { SetValue(PreviousButtonStyleProperty, value); }
}
private static void OnPreviousButtonStyleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((MonthCalendar)d).RefreshPreviousButtonStyle();
}
/**//// <summary>
/// The DependencyProperty for the NextButtonStyle property.
/// Flags: none
/// Default Value: null
/// </summary>
public static readonly DependencyProperty NextButtonStyleProperty =
DependencyProperty.Register(
"NextButtonStyle",
typeof(Style),
typeof(MonthCalendar),
new FrameworkPropertyMetadata(
(Style)null, new PropertyChangedCallback(OnNextButtonStyleChanged)));
/**//// <summary>
/// NextButtonStyle property
/// </summary>
public Style NextButtonStyle
{
get { return (Style)GetValue(NextButtonStyleProperty); }
set { SetValue(NextButtonStyleProperty, value); }
}
private static void OnNextButtonStyleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((MonthCalendar)d).RefreshNextButtonStyle();
}