0

我想读取在 NumericUpDown 控件中输入的值。我怎么读?

XAML 布局如下

  <StackPanel Style="{StaticResource StackPanelStyle_LableValue}">
                            <TextBlock Style="{StaticResource TextBlockStyle}" 
                                       Text="{Binding Path=ViewItem.Addition, Source={StaticResource LocalizedStrings }}" />
                            <inputToolkit:NumericUpDown Style="{StaticResource NumericUpdownStyle_Addition}"
                                                        Value="{Binding Items.RightSpecGlass.Addition, Mode=TwoWay}" 
                                                        TabIndex="8" />
                        </StackPanel>
4

2 回答 2

1

您可以使用

numericUpDown.Value; // To get decimal value of control

或者

numericUpDown.Text; // To get value as string of control
于 2011-08-12T12:16:15.283 回答
0

好吧,既然你已经绑定了你的视图上下文,我认为没有理由避免获取 NumericUpDown 的值,除了:

1-也许您忘记初始化这些类或属性Items和/或RightSpecGlass

2-当任何控件的值在视图中发生变化时,您的类不会实现INotifyPropertyChanged引发。Addition属性必须在其设置器中引发属性更改事件。

    public event PropertyChangedEventHandler PropertyChanged;
    public virtual void RaisePropertyChanged(string propertyName)
    {
        var handler = PropertyChanged;
        if (handler != null)
            handler(this, new PropertyChangedEventArgs(propertyName));
    }
    private int _addition;
    public Int32 Addition
    {
        get { return _addition; }
        set
        {
            _addition= value;
            RaisePropertyChanged("Addition");
        }
    }

希望这有帮助。

于 2011-08-16T04:46:07.353 回答