using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace HBLConsole.PryUserControl
{
///
/// BeveledButton.xaml 的交互逻辑
///
public partial class BeveledButton : UserControl
{
public BeveledButton()
{
InitializeComponent();
}
public static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
(d as BeveledButton).Refresh();
}
///
/// 依赖属性更改的委托
///
private void Refresh()
{
this.poly.Fill = FillColor;
this.poly.StrokeThickness = StrokeThickness;
this.poly.Stroke = Stroke;
}
#region FillColor:填充颜色 依赖属性
///
/// 填充颜色
///
public Brush FillColor
{
get { return (Brush)GetValue(FillColorProperty); }
set { SetValue(FillColorProperty, value); }
}
public static readonly DependencyProperty FillColorProperty =
DependencyProperty.Register("FillColor", typeof(Brush), typeof(BeveledButton),
new PropertyMetadata(default(Brush), new PropertyChangedCallback(OnPropertyChanged)));
#endregion
#region 外边线宽度
///
/// 外边线宽度
///
public int StrokeThickness
{
get { return (int)GetValue(StrokeThicknessProperty); }
set { SetValue(StrokeThicknessProperty, value); }
}
public static readonly DependencyProperty StrokeThicknessProperty =
DependencyProperty.Register("StrokeThickness", typeof(int), typeof(BeveledButton),
new PropertyMetadata(0, new PropertyChangedCallback(OnPropertyChanged)));
#endregion
#region 外边框颜色
///
/// 外边框颜色
///
public Brush Stroke
{
get { return (Brush)GetValue(StrokeProperty); }
set { SetValue(StrokeProperty, value); }
}
public static readonly DependencyProperty StrokeProperty =
DependencyProperty.Register("Stroke", typeof(Brush), typeof(BeveledButton),
new PropertyMetadata(default(Brush), new PropertyChangedCallback(OnPropertyChanged)));
#endregion
#region 输入文本
public string Text
{
get { return (string)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register("Text", typeof(string), typeof(BeveledButton),
new PropertyMetadata(string.Empty, new PropertyChangedCallback(OnPropertyChanged)));
#endregion
#region 设置是否是平行四边形
public bool IsParallelogram
{
get { return (bool)GetValue(IsParallelogramProperty); }
set { SetValue(IsParallelogramProperty, value); }
}
public static readonly DependencyProperty IsParallelogramProperty =
DependencyProperty.Register("IsParallelogram", typeof(bool), typeof(BeveledButton),
new PropertyMetadata(false, new PropertyChangedCallback(OnPropertyChanged)));
#endregion
private void Canvas_SizeChanged(object sender, SizeChangedEventArgs e)
{
PointCollection points = new PointCollection();
points.Add(new Point(0, 0));
points.Add(new Point(e.NewSize.Width - (e.NewSize.Height / 2), 0));
points.Add(new Point(e.NewSize.Width, e.NewSize.Height));
points.Add(new Point(IsParallelogram ? (e.NewSize.Height / 2) : 0, e.NewSize.Height));
this.poly.Points = points;
//this.tb.Text = Text;
}
}
}