0

I'm trying to folow the mvvm pattern. When using galasoft EventToCommand i'm getting then following error: The best overloaded method match for 'GalaSoft.MvvmLight.Command.RelayCommand.RelayCommand(System.Action)' has some invalid arguments...

Code from my XAML:

<toolkit:DatePicker Header="Select Date" 
     ValueStringFormat="{}{0:D}"                                    
     HorizontalAlignment="Left" Margin="0,126,0,0" 
     Name="datePicker1" 
     VerticalAlignment="Top" FontFamily="Verdana"  
     FontSize="22" Width="450">
     <i:Interaction.Triggers>
          <i:EventTrigger EventName="ValueChanged">
               <cmd:EventToCommand PassEventArgsToCommand="True"
                     Command="{Binding DateSelection}"/>
          </i:EventTrigger>
     </i:Interaction.Triggers>
</toolkit:DatePicker>

In the modelview:

  public MainViewModel()
    {
        DateSelection = new RelayCommand<DateTimeValueChangedEventArgs>(time_Call);
    }

    public RelayCommand<DateTimeValueChangedEventArgs> DateSelection
    {
        get;
        set;
    }
    void time_Call(object sender, DateTimeValueChangedEventArgs e)
    {

    }

I'm blank!

iCollect.it Ltd
  • 92,391
  • 25
  • 181
  • 202

1 Answers1

0

Can you Two-Way bind to the Value property instead? This would simplify things and let you use the true power of XAML and MVVM... binding.

<toolkit:DatePicker Header="Select Date" 
     ValueStringFormat="{}{0:D}"                                    
     HorizontalAlignment="Left" Margin="0,126,0,0" 
     Name="datePicker1" 
     VerticalAlignment="Top" FontFamily="Verdana"  
     FontSize="22" Width="450"
Value={Binding SelectedDate, Mode=TwoWay}" />

The view model

  private DateTime selectedDate;
    public DateTime SelectedDate
    {
        get
        {
          return this.selectedDate;
        }

        set
        {
          if (this.selectedDate != value)
          {
            this.selectedDate = value;
            this.RaisePropertyChanged("SelectedDate");
          }
        }
    }

    public MainViewModel()
    {
// initialize to today being selected
this.SelectedDate = DateTime.Now;
// the property changed might not be necessary if you are just trying to get the new value
    this.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(MainViewModel_PropertyChanged);
    }

    void MainViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
    {
      if(e.PropertyName="SelectedDate")
    {
    // do something if needed
    }
    }
AlignedDev
  • 8,102
  • 9
  • 56
  • 91
  • I properly could set it up with databinding. But when using the toolkit I'm coupled off from the View - so using "this." to gain access to the object form the View wont work. After some time debugging I found out what I was missing. I need to invoke the time_Call method and use a delegate. The solution was to use a Lambda to spawn a delegate: ( e=> "My method" ). However I don't like this syntax, I find it to implicit. – Theodor Heiselberg May 31 '12 at 07:33