0
我正在致力于UserControl
,其中我有MaximumAngle
和MinimumAngle
属性。必须不同的两个UserControl依赖项属性
// MinimumAngle
public double MinimumAngle
{
get { return (double)GetValue(MinimumAngleProperty); }
set { SetValue(MinimumAngleProperty, value); }
}
public static readonly DependencyProperty MinimumAngleProperty = DependencyProperty.Register(
"MinimumAngle", typeof(double), typeof(RoundGauge), new PropertyMetadata((double)0, MinimumAnglePropertyChanged));
private static void MinimumAnglePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
RoundGauge rg = (RoundGauge)d;
rg.CreateTickLines();
}
// MaximumAngle
public double MaximumAngle
{
get { return (double)GetValue(MaximumAngleProperty); }
set { SetValue(MaximumAngleProperty, value); }
}
public static readonly DependencyProperty MaximumAngleProperty = DependencyProperty.Register(
"MaximumAngle", typeof(double), typeof(RoundGauge), new PropertyMetadata((double)180, MaximumAnglePropertyChanged));
private static void MaximumAnglePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
RoundGauge rg = (RoundGauge)d;
rg.CreateTickLines();
}
这些属性必须是不同的,因为我的CreateTickLines
方法要疯了,当它具有处理为零。
我可以用这个做什么?
使用属性元数据注册[CoerceValueCallback](https://msdn.microsoft.com/en-us/library/system.windows.coercevaluecallback(v = vs.110).aspx)。 – Clemens
您可以使用MSDN页面[依赖属性回调和验证](https://msdn.microsoft.com/en-us/library/ms745795(v = vs.110).aspx)中描述的“ValidateValueCallback” – Rachel