希望通过分析能更好的理解wpf控件的开发
一.日历的header布局
包含两部分,两个按钮和一个Title
首先定义按钮的样式(随自己定),可以先定义几个状态为普通状态,鼠标经过状态,按下状态和禁用4个状态显示不同的样式.其中按钮上还有一个小三角.所以还要定义一个三角的Geometry
代码开始
1.画出Geometry(涉及知识点为Geometry的画法及迷你语法,如M Z等)
<PathGeometry x:Key="geometry" Figures="M0,0 4.5,4 9,0 5.5,0 4.5,1 3.5,0z"/>
2.定义4个不同状态下的笔刷(可自由发挥)
Code
<LinearGradientBrush x:Key="MonthCalendarButtonFillNormal" StartPoint="0,0" EndPoint="1,1">
<LinearGradientBrush.GradientStops>
<GradientStop Color="#FFE1EAFE" Offset="0"/>
<GradientStop Color="#FFC3D3FD" Offset="0.3"/>
<GradientStop Color="#FFC3D3FD" Offset="0.6"/>
<GradientStop Color="#FFBBCDF9" Offset="1"/>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
<LinearGradientBrush x:Key="MonthCalendarButtonFillHover" StartPoint="0, 0" EndPoint="1, 1">
<LinearGradientBrush.GradientStops>
<GradientStop Color="#FFD6E7FF" Offset="0"/>
<GradientStop Color="#FFD6E7FF" Offset="0.6"/>
<GradientStop Color="#FFB9DAFB" Offset="1"/>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
<LinearGradientBrush x:Key="MonthCalendarButtonFillPressed" StartPoint="0, 0" EndPoint="1, 1">
<LinearGradientBrush.GradientStops>
<GradientStop Color="#FF93A8D9" Offset="0"/>
<GradientStop Color="#FFA5BDFB" Offset="0.3"/>
<GradientStop Color="#FFA5BDFB" Offset="0.7"/>
<GradientStop Color="#FFD2DEEB" Offset="1.0"/>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
<LinearGradientBrush x:Key="MonthCalendarButtonFillDisabled" StartPoint="0, 0" EndPoint="1, 1">
<LinearGradientBrush.GradientStops>
<GradientStop Color="#FFF7F7F7" Offset="0"/>
<GradientStop Color="#FFF0F0F0" Offset="0.3"/>
<GradientStop Color="#FFECECEC" Offset="0.6"/>
<GradientStop Color="#FFE3E3E3" Offset="1.0"/>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>