69 lines
2.1 KiB
C#
69 lines
2.1 KiB
C#
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
|
|
namespace Zerolauncher.controls
|
|
{
|
|
/// <summary>
|
|
/// 按照步骤 1a 或 1b 操作,然后执行步骤 2 以在 XAML 文件中使用此自定义控件。
|
|
///
|
|
/// 步骤 1a) 在当前项目中存在的 XAML 文件中使用该自定义控件。
|
|
/// 将此 XmlNamespace 特性添加到要使用该特性的标记文件的根
|
|
/// 元素中:
|
|
///
|
|
/// xmlns:MyNamespace="clr-namespace:Zerolauncher.controls"
|
|
///
|
|
///
|
|
/// 步骤 1b) 在其他项目中存在的 XAML 文件中使用该自定义控件。
|
|
/// 将此 XmlNamespace 特性添加到要使用该特性的标记文件的根
|
|
/// 元素中:
|
|
///
|
|
/// xmlns:MyNamespace="clr-namespace:Zerolauncher.controls;assembly=Zerolauncher.controls"
|
|
///
|
|
/// 您还需要添加一个从 XAML 文件所在的项目到此项目的项目引用,
|
|
/// 并重新生成以避免编译错误:
|
|
///
|
|
/// 在解决方案资源管理器中右击目标项目,然后依次单击
|
|
/// “添加引用”->“项目”->[浏览查找并选择此项目]
|
|
///
|
|
///
|
|
/// 步骤 2)
|
|
/// 继续操作并在 XAML 文件中使用控件。
|
|
///
|
|
/// <MyNamespace:AirButton/>
|
|
///
|
|
/// </summary>
|
|
|
|
public class AirButton : Button
|
|
{
|
|
static AirButton()
|
|
{
|
|
//DefaultStyleKeyProperty.OverrideMetadata(typeof(AirButton), new FrameworkPropertyMetadata(typeof(AirButton)));
|
|
}
|
|
|
|
protected override void OnMouseEnter(MouseEventArgs e)
|
|
{
|
|
// 不执行任何操作
|
|
}
|
|
|
|
protected override void OnMouseLeave(MouseEventArgs e)
|
|
{
|
|
// 不执行任何操作
|
|
}
|
|
|
|
protected override void OnMouseDown(MouseButtonEventArgs e)
|
|
{
|
|
base.OnMouseDown(e);
|
|
this.RenderTransform = new TranslateTransform(3, 3);
|
|
}
|
|
|
|
protected override void OnMouseUp(MouseButtonEventArgs e)
|
|
{
|
|
base.OnMouseUp(e);
|
|
this.RenderTransform = new TranslateTransform(0, 0);
|
|
}
|
|
}
|
|
|
|
}
|