|
- 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
- {
- /// <summary>
- /// Quadrilateral.xaml 的交互逻辑
- /// </summary>
- public partial class Quadrilateral : UserControl
- {
- public Quadrilateral()
- {
- InitializeComponent();
- }
-
-
- public static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- (d as Quadrilateral).Refresh();
- }
-
- /// <summary>
- /// 依赖属性更改的委托
- /// </summary>
- private void Refresh()
- {
- this.poly.Fill = FillColor;
- this.poly.StrokeThickness = StrokeThickness;
- this.poly.Stroke = Stroke;
- }
-
- #region FillColor:填充颜色 依赖属性
- /// <summary>
- /// 填充颜色
- /// </summary>
- 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 外边线宽度
- /// <summary>
- /// 外边线宽度
- /// </summary>
- 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 外边框颜色
- /// <summary>
- /// 外边框颜色
- /// </summary>
- 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;
- }
- }
- }
|