[TemplatePart(Name = "Part_Root", Type = typeof(Panel))]
[TemplatePart(Name = "Part_Caption", Type = typeof(TextBlock))]
[TemplatePart(Name = "Part_ForegroundRect", Type = typeof(Rectangle))]
[TemplatePart(Name = "Part_BackgroundRect", Type = typeof(Rectangle))]
[TemplatePart(Name = "Part_HighlightRect", Type = typeof(Rectangle))]
[TemplatePart(Name = "Part_MouseEnter", Type = typeof(Storyboard))]
[TemplatePart(Name = "Part_MouseLeave", Type = typeof(Storyboard))]
[TemplatePart(Name = "Part_MouseDown", Type = typeof(Storyboard))]
[TemplatePart(Name = "Part_MouseUp", Type = typeof(Storyboard))]
public abstract partial class ButtonBase : Control
{
/// <summary>
/// 定义单击事件
/// </summary>
public event EventHandler Click;
/// <summary>
/// 执行单击事件的绑定方法
/// </summary>
protected void OnClick()
{
if (Click != null)
{
Click(this, new EventArgs());
}
}
/// <summary>
/// 标题属性
/// </summary>
public string Caption
{
get { return this.Part_Caption.Text; }
set { this.Part_Caption.Text = value; }
}
/// <summary>
/// 鼠标移入控件区域时启动Part_MouseEnter故事板,下面类似
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected virtual void Part_Root_MouseEnter(object sender, MouseEventArgs e)
{
Part_MouseEnter.Begin();
}
protected virtual void Part_Root_MouseLeave(object sender, MouseEventArgs e)
{
Part_MouseLeave.Begin();
}
protected virtual void Part_Root_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
Part_MouseDown.Begin();
}
protected virtual void Part_Root_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
Part_MouseUp.Begin();
//执行单击事件的绑定方法
OnClick();
}
protected Storyboard Part_MouseEnter, Part_MouseDown, Part_MouseLeave, Part_MouseUp;
protected Rectangle Part_ForegroundRect, Part_BackgroundRect, Part_HighlightRect;
protected Panel Part_Root;
protected TextBlock Part_Caption;
}