2

Silverlight Toolkit の NumericUpDown コントロールが MVVM プロパティにバインドされ、RelayCommand トリガーが設定されている場合 (任意のイベント)、NumericUpDown が MVVM プロパティの値を変更する前にコマンドが呼び出されます。これは、メソッド/アクション/コマンドで新しい (変更された) 値を使用できないことを意味します...

XAML:

<inputToolkit:NumericUpDown x:Name="testNum" Value="{Binding RegisterForm, Mode=TwoWay}">
<i:Interaction.Triggers>
  <i:EventTrigger EventName="ValueChanged">
    <GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding DoSomethingCommand}"/>
  </i:EventTrigger>
</i:Interaction.Triggers>
</inputToolkit:NumericUpDown>

MVVM (C#):

DoSomethingCommand = new RelayCommand(() =>
            {
                OtherRegisterForm = RegisterForm;
            });

この場合、v 値が 0 で、NumericUpDown コントロールに新しい値 123 を入力すると、MVVM プロパティの「RaisePropertyChange」イベントの前に「DoSomethingCommand」がトリガーされます。「OtherRegisterForm」は 123 ではなく 0 になります。

これを機能させる方法はありますか?

4

1 に答える 1

1

oh boy, wasn't easy but here u are :

xaml part :

<toolkit:NumericUpDown Value="{Binding SomeNumber}">
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="ValueChanged">
                <GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding MyCommand}" PassEventArgsToCommand="True" />
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </toolkit:NumericUpDown>

and cs code :

    public class MainViewModel : ViewModelBase
{

    public double SomeNumber { get; set; }

    public MainViewModel()
    {
        SomeNumber = 10;
        MyCommand = new RelayCommand<RoutedPropertyChangedEventArgs<double>>(myActionMethod);
    }

    public RelayCommand<RoutedPropertyChangedEventArgs<double>> MyCommand { get; set; }

    public void myActionMethod(RoutedPropertyChangedEventArgs<double> arg)
    {
        MessageBox.Show(arg.NewValue.ToString());
    }
}

hope that helps, Arek

于 2010-12-03T11:48:22.727 に答える