What you are trying to do is a pretty serious violation of the whole MVVM, but it is possible ...
With the following lines in your view code, you can ...
... access the resource line:
var scanName = this.Resources["scanName"];
... access to ViewModel:
var vm = DataContext as MyViewModel; if (vm == null) return; vm.ScanHistory.Add(scanName);
Having said that, you really should not do this. The idea behind MVVM is to completely disable ViewModel and View and allow WPF binding mechanisms to connect them for you. In your case, as far as I can tell, you should save the scan name somewhere else, either as a resource or as a configuration value, get it in your ViewModel and provide a property on the ViewModel to which your view can bind.
source share