I have a button on my usercontrol
<Button Grid.Row="13" Grid.Column="7" Content="Save" Name="btnSave"
CommandParameter="{Binding CompanyDetails}"
Command="{Binding SaveCommand}" />
SaveCommand is a RelayCommand declared in the ViewModel. CompanyDetails is a property in the same ViewModel. The mentioned above ViewModel is the datacontext of my UserControl.
Public Class CompanyViewModel
Inherits ViewModelBase
Implements IDataErrorInfo
Private _myData As DataFromDatabase
Private _companyDetails As New CompanyDetailsBase
Private _saveCommand As RelayCommandWithParameter
Public Property CompanyDetails() As CompanyDetailsBase
Get
Return _companyDetails
End Get
Set(ByVal value As CompanyDetailsBase)
_companyDetails = value
OnPropertyChanged("CompanyDetails")
End Set
End Property
Public Property SaveCommand() As RelayCommandWithParameter
Get
If _saveCommand Is Nothing Then
Dim saveAction As New Action(Of Object)(AddressOf Me.SaveIt)
_saveCommand = New RelayCommandWithParameter(saveAction) ', Me.CanSave)
End If
Return _saveCommand
End Get
Set(ByVal value As RelayCommandWithParameter)
_saveCommand = value
End Set
End Property
Public Sub New()
_myData = New DataFromDatabase(My.Settings.ConnectionString)
_saveCommand = New RelayCommandWithParameter(New Action(Of Object)(AddressOf SaveIt))
End Sub
Public Function GetCompanyDetails(ByVal sap As String) As CompanyDetailsBase
CompanyDetails = _myData.GetCompanyDetails(sap)
Return CompanyDetails
End Function
Public Sub SaveIt(ByVal c As CompanyDetailsBase)
MessageBox.Show("Save customer " & c.Sap)
End Sub
End Class
The other fields on the usercontrol are bound to an ObjectDataProvider, which calls the GetCompanyDetails function. The CompanyDetails is set right each time this function is called, until I call SaveIt subroutine. When SaveIt is called its parameter is always Nothing. Where do I make the mistake? Thank you a lot for answers.