自己写个 Sharp 对象练练手

自己写个 Sharp 对象练练手 

要在屏幕呈现不同内容 关键是 如何实现  Geometry DefiningGeometry  返回的 _lineGeometry对象!

这里暂时用  lineGeometry 画条值线

/*****************************************************************************************************
 * 本代码版权归 kmsmg 所有,All Rights Reserved (C) 2018-2066
 *****************************************************************************************************
 * 所属域: 
 * 登录用户: 
 * CLR版本:4.0.30319.42000
 * 唯一标识:ffc701e9-5424-4940-9d9a-0675c2570f4e
 * 机器名称: 
 * 联系人邮箱: 
 *****************************************************************************************************
 * 命名空间:WpfApplication2
 * 类名称:XLine
 * 文件名:XLine
 * 创建年份:2019
 * 创建时间:2019/5/2 22:44:40
 * 创建人: kmsmg
 * 创建说明:
 *********************************    每次修订添加记录项  *************************************************
 * 修改人:
 * 修改时间:
 * 修改说明:
 * 
 * 修订版本:
*****************************************************************************************************/



 
using System.Windows.Shapes;
using System.Windows;
using System.Windows.Media;
using System.ComponentModel;
 

namespace WpfApplication2
{
    /// <summary>
    /// The XLine shape element
    /// This element (like all shapes) belongs under a Canvas,
    /// and will be presented by the parent canvas.
    /// </summary>
    public sealed class XLine : Shape
    {

        #region Constructors

        /// <summary>
        /// Instantiates a new instance of a line.
        /// </summary>
        public XLine()
        {
           
        }

        #endregion Constructors

        #region Dynamic Properties

        /// <summary>
        /// X1 property
        /// </summary>
        public static readonly DependencyProperty X1Property =
            DependencyProperty.Register("X1", typeof(double), typeof(XLine),
                new FrameworkPropertyMetadata(0d, FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender)
                //, new ValidateValueCallback(Shape.IsDoubleFinite)
                );

        /// <summary>
        /// X1 property
        /// </summary>
        [TypeConverter(typeof(LengthConverter))]
        public double X1
        {
            get
            {
                return (double)GetValue(X1Property);
            }
            set
            {
                SetValue(X1Property, value);
            }
        }

        /// <summary>
        /// Y1 property
        /// </summary>
        public static readonly DependencyProperty Y1Property =
            DependencyProperty.Register("Y1", typeof(double), typeof(XLine),
                new FrameworkPropertyMetadata(0d, FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender)
              // , new ValidateValueCallback(Shape.IsDoubleFinite)
                );

        /// <summary>
        /// Y1 property
        /// </summary>
        [TypeConverter(typeof(LengthConverter))]
        public double Y1
        {
            get
            {
                return (double)GetValue(Y1Property);
            }
            set
            {
                SetValue(Y1Property, value);
            }
        }

        /// <summary>
        /// X2 property
        /// </summary>
        public static readonly DependencyProperty X2Property =
            DependencyProperty.Register("X2", typeof(double), typeof(XLine),
                new FrameworkPropertyMetadata(0d, FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender)
               //, new ValidateValueCallback(Shape.IsDoubleFinite)
                );

        /// <summary>
        /// X2 property
        /// </summary>
        [TypeConverter(typeof(LengthConverter))]
        public double X2
        {
            get
            {
                return (double)GetValue(X2Property);
            }
            set
            {
                SetValue(X2Property, value);
            }
        }

        /// <summary>
        /// Y2 property
        /// </summary>
        public static readonly DependencyProperty Y2Property =
            DependencyProperty.Register("Y2", typeof(double), typeof(XLine),
                new FrameworkPropertyMetadata(0d, FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender)
              //,   new ValidateValueCallback(Shape.IsDoubleFinite)
              );

        /// <summary>
        /// Y2 property
        /// </summary>
        [TypeConverter(typeof(LengthConverter))]
        public double Y2
        {
            get
            {
                return (double)GetValue(Y2Property);
            }
            set
            {
                SetValue(Y2Property, value);
            }
        }


        #endregion Dynamic Properties

        #region Protected Methods and Properties


        /// <summary>
        /// Get the line that defines this shape
        /// </summary>
        protected override Geometry DefiningGeometry
        {
            get
            {
                if (_lineGeometry==null)
                {
                    Point point1 = new Point(X1, Y1);
                    Point point2 = new Point(X2, Y2);

                    // Create the Line geometry
                    _lineGeometry = new LineGeometry(point1, point2);
                }
                return _lineGeometry;
            }
        }

        #endregion
        #region Private Methods and Members

        private LineGeometry _lineGeometry;

        #endregion
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值