【问题标题】:How do I read Text property of silverlight toolkit NumericUpDown control?如何读取 silverlight 工具包 NumericUpDown 控件的 Text 属性?
【发布时间】:2011-08-12 12:11:03
【问题描述】:

我想读取在 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>

【问题讨论】:

  • 你设置视图的数据上下文了吗?
  • @S.Amani 是的,我已经设置好了。我想读取 XAML 后面代码中的值
  • 所以你想通过绑定来获得它的价值,是吗?
  • 你发起过那些东西吗?我的意思是 Items 和 RightSpecGlass ?
  • @S.Amani 一切正常。我的系统出现错误。那是我们为荷兰文化设计的 UpDownControl,因此它接受 1,2 作为数字,但是当用户输入 1.2 时,它在 updown 控制中显示 12,我希望 1.2 在内部转换为 1,2。请参考stackoverflow.com/questions/7039529/…

标签: c# silverlight toolkit numericupdown


【解决方案1】:

你可以使用

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

numericUpDown.Text; // To get value as string of control

【讨论】:

  • 他想绑定NumericUpDown的值而不是直接通过命名控件来获取它的值。
【解决方案2】:

好吧,既然你已经绑定了你的视图上下文,我认为没有理由避免获取 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");
        }
    }

希望对您有所帮助。

【讨论】:

  • 我已经使用 View Model 了,它工作正常。我在这个问题stackoverflow.com/questions/7039529/… 中描述了一个错误。一旦我将获得在数字控件中输入的字符串值,我就可以根据需要对其进行解析。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多