2

Si un contrôle Silverlight Toolkit NumericUpDown est lié à une propriété MVVM et à un ensemble de déclencheurs RelayCommand (tout événement), la commande est appelée avant que NumericUpDown ne modifie la valeur de la propriété MVVM. Cela signifie, vous ne pouvez pas utiliser le nouveau (changé) valeur avec vous méthode/action/commande ...Commandes MVVM Relay avant que Silverlight NumericUpDown change de valeur

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; 
      }); 

Dans ce Si vous avez la valeur 0 et que vous entrez une nouvelle valeur 123 dans le contrôle NumericUpDown, il déclenche l'événement "DoSomethingCommand" avant l'événement "RaisePropertyChange" sur la propriété MVVM. "OtherRegisterForm" serait 0 et non 123.

Existe-t-il un moyen de rendre ce travail?

Répondre

1

oh boy, n'a pas été facile, mais ici u sont:

XAML partie:

<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> 

et le code cs:

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()); 
    } 
} 

espoir qui aide, Arek