silverlight中为控件添加可以在标签中设置的属性

public static readonly DependencyProperty ExcerciseStatusProperty;
        static comCoreDamage()
        {

            ExcerciseStatusProperty = DependencyProperty.Register("ExcerciseStatus",
                                           typeof(int),
                                           typeof(comCoreDamage),
                                           new PropertyMetadata(2, new PropertyChangedCallback(comCoreDamage.OnTextPropertyChanged)));
        }
        
        //此控件的C#属性
        public int ExcerciseStatus
        {
            get
            {
                return (int)base.GetValue(ExcerciseStatusProperty);
            }
            set
            {
                base.SetValue(ExcerciseStatusProperty, value);
            }
        }

        private static void OnTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ////是否为编辑态
            if (!DesignerProperties.IsInDesignTool)
            {
                (d as comCoreDamage).OnTextPropertyChanged(e);
            }
        }

        void OnTextPropertyChanged(DependencyPropertyChangedEventArgs e)
        {
            try
            {
                curExcerciseStatus = (int)e.NewValue;
            }
            catch (Exception ex)
            {
                string ks = ex.ToString();
            }

        }
        #endregion
View Code

 

posted on 2013-07-22 18:33  中子持心  阅读(278)  评论(0)    收藏  举报

导航