【问题标题】:Updating NumericUpDown value according to another NumericUpDown control根据另一个 NumericUpDown 控件更新 NumericUpDown 值
【发布时间】:2014-08-19 09:31:02
【问题描述】:

伙计们,如果我的 XAML 中有 2 个数字上下颠倒,就像这样

<Input:SfNumericUpDown Grid.Column="1" Margin="10,0,10,0"  Value="{Binding CompoundQty}" ValueChanged="SfNumericUpDown_ValueChanged"/>
<Input:SfNumericUpDown Grid.Column="4" Margin="10,0,10,0" Value="{Binding ResultQty}" Tag="{Binding ItemID}" />

我希望根据第一个 numericupdown 值更改第二个 numericupdown 值。 我试着把它放在后面的代码中。

private void SfNumericUpDown_ValueChanged(object sender, Syncfusion.UI.Xaml.Controls.Input.ValueChangedEventArgs e)
    {
        var numCompoundQty = (SfNumericUpDown)sender;
        foreach(var row in _entityEdited.ListCompoundDisplay)
        {
            if(row.ItemID == Convert.ToInt32(numCompoundQty.Tag))
            {
                row.CompoundQty = Convert.ToDecimal(numCompoundQty.Value);
                row.ResultQty = Convert.ToDecimal(numDispenseQty.Value) * row.CompoundQty;
                break;
            }
        }



    }

但它不起作用,你们能帮我解决什么问题吗?

【问题讨论】:

  • 您是否提高了属性的正确 notifypropertychanged?
  • 我没有使用任何 notifypropertychanged 函数先生...

标签: c# silverlight xaml windows-phone-8


【解决方案1】:

您将在此处遇到问题,因为您尝试引用一个名为“numDispenseQty”的元素,而您无权访问该元素(假设它位于 DataTemplate 中)。您应该使用与视图模型的双向绑定,而不是处理“值更改”事件:

<Input:SfNumericUpDown Value="{Binding CompoundQty,Mode=TwoWay}" />

现在将更新逻辑放入“CompoundQty”属性的设置器中,例如:

public double CompoundQty
{
    get { return _compoundQty; }
    set
    { 
        _compoundQty = value;
        UpdateResultQty();
        RaisePropertyChanged("CompoundQty");
    }
}

private void UpdateResultQty()
{
    ResultQty = DispenseQty * CompoundQty;
}

请注意(如@sslazio1900 所述)您的视图模型类必须实现INotifyPropertyChanged,并在属性更改时引发PropertyChanged 事件(视图知道如何自我更新)。

【讨论】:

    【解决方案2】:

    尝试在两个属性上引发 NotifiyPropertyChanged 事件。

    如果没有,Binding Engine 无法检测到值更改,您将永远无法更新您的值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多