相关疑难解决方法(0)

如何处理 DependencyProperty 溢出情况?

我有一个UserControl和一个DependencyProperty名为 Value的 int 。这绑定到UserControl.

public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(int), typeof(QuantityUpDown), new FrameworkPropertyMetadata(0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnValueChanged, CoerceValue));

public int Value
{
    get { return (int) GetValue(ValueProperty); }
    set { SetValue(ValueProperty, value); }
}

private static object CoerceValue(DependencyObject d, object basevalue)
{
    //Verifies value is not outside Minimum or Maximum
    QuantityUpDown upDown       = d as QuantityUpDown;
    if (upDown == null)
        return basevalue;

    if ((int)basevalue <= 0 && upDown.Instrument != null)
        return upDown.Minimum;

    //Stocks and …
Run Code Online (Sandbox Code Playgroud)

c# wpf

0
推荐指数
1
解决办法
1552
查看次数

标签 统计

c# ×1

wpf ×1