最近寫程序時用到Calendar控件,程序中由於是要用到觸屏所以需要大一點的日歷,
因為平時用到Calendar時都是直接拖出來就可以了,所以也沒去關注太多關於Calendar的屬
性;由於我也是接觸WPF時間不長,所以擺置了半天關於Calendar的風格,於是就把它寫在了博客
,完全是給一些新手看的,希望對其有所幫助,也算是一種交流吧,
可能還有很多不足,但主要是給一些新手提供一些小的信息,至於怎么發揮還在自己了^^。
1.將Calendar變大
首先在 Microsoft Expression Blend 4 中拖一個Calendar控件,然后在其上面右鍵
選擇 Edit Template(編輯模板)中的Edit a Copy...,之后就進入控件的內部,然后在XAML中
將<stackpanel/>標簽刪除,注意<stackpanel/>里面還有一個<CalendarItem/>不要刪了,只刪除<stackpanel/>
2.設置Calendar的CalendarDayButton屬性
第一步做完后,然后建一個資源,關於CalendarDayButton的一個資源,如下:
<window.Resources>
<Style TargetType="CalendarDayButton" x:Key="calendardayButton">
<Style.Triggers>
<EventTrigger RoutedEvent="CalendarDayButton.Click">
<!--<sele Property="IsVisible" Value="false"/>-->
</EventTrigger>
</Style.Triggers>
<Setter Property="Width" Value="70"/>
<Setter Property="Height" Value="70"/>
<Setter Property="FontSize" Value="20"/>
<Setter Property="Foreground" Value="Blue"/>
<!--<Setter Property="Background" Value="White"/>-->
<Setter Property="Background">
<Setter.Value>
<RadialGradientBrush>
<GradientStop Color="#FFA1A1A1" Offset="0"/>
<GradientStop Color="#FF8BABCE" Offset="0.8"/>
<GradientStop Color="#FF8BABCE" Offset="1"/>
</RadialGradientBrush>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
然后在Calendar的CalendarDayButton屬性中引用資源: CalendarDayButtonStyle="{StaticResource calendardayButton}"
然后就OK了
*********************************************************************
希望一些高手能夠傳授WPF的一些關於學習上的建議和指點。