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 BPASmartClient.CustomResource.UserControls { /// /// Quadrilateral.xaml 的交互逻辑 /// public partial class Quadrilateral : UserControl { public Quadrilateral() { InitializeComponent(); } public static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { (d as Quadrilateral).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(Quadrilateral), 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(Quadrilateral), 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(Quadrilateral), new PropertyMetadata(default(Brush), 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(e.NewSize.Height / 2, e.NewSize.Height)); this.poly.Points = points; } } }