簡體   English   中英

如何讀取 silverlight 工具包 NumericUpDown 控件的 Text 屬性?

[英]How do I read Text property of silverlight toolkit NumericUpDown control?

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

您可以使用

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

或者

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

好吧,既然你已經綁定了你的視圖上下文,我認為沒有理由避免獲取 NumericUpDown 的值,除了:

1-也許你忘了初始化那些類或屬性Items和/或RightSpecGlass

2-您的 class 未實現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");
        }
    }

希望這有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM