I am creating an application using .Net and MVVM Light and I am having some trouble for RelayCommands.
I'm trying to create a RelayCommand which takes in a single argument and passes it to a function within the same ViewModel. However everytime I try and do this I keep getting the following exception:
A first chance exception of type 'System.MethodAccessException' occurred in mscorlib.dll
My code is below.
XAML
<TextBlock Style="{StaticResource QueryFormTab}" >
<Hyperlink Command="{Binding TestCommand}" CommandParameter="Tester">
Test
</Hyperlink>
</TextBlock>
ViewModel
public RelayCommand<string> TestCommand { get; private set; }
// in the constructor
TestCommand = new RelayCommand<string>((param) => _testExecute(param));
// function in viewmodel
private void _testExecute(string s)
{
Trace.WriteLine("Test");
ViewModelVariable = "abc";
}
If I make the function _testExecute static it works however I am unable to access any of the other functions within my viewmodel.
I have been trying to figure this out for a while now but not had any luck.