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