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.
Test
hyperlink worked perfectly with no fidgeting or anything ... Either your locator wasn't defined, or your data context wasn't right, or you didn't have the right MVVM-Light files. If you want to try and solve it, leave a message and I'll see if I can help. (or, you can just use your own implementation as well :) – Magalymagan