/* BeejBløg */

Oct 4, 2016 - 2 minute read - Comments -

Toggle XAML <> Code-Behind in Visual Studio 2015, ReSharper, Xamarin Forms

Quickly bouncing between .XAML and corresponding .CS file just seems like an obvious need… i feel like we used to have this in WPF but it’s been a few years for me.

Short Story:

  • this approach simply maps preferred hotkey to ReSharper’s “Go To Related Files” command… sorry if that’s not an expense you care to bear but it’s a great tool for numerous reasons if you can spring for it
  • Visual Studio > Tools menu > Options > Environment > Keyboard
  • “Show commands containing” edit box enter: relatedfiles
  • select “ReSharper.ReSharper_GotoRelatedFiles”
  • “Use new shortcut in” drop down select: Text Editor
  • “Press shortcut keys” edit box press: F7
  • lastly click “Assign” button and “OK” and you’re done



ViewModel class in .xaml.cs file

if you happen to be using the Prism framework’s automatic ViewModel binding, consider throwing your ViewModel (VM) classes into the {View}.xaml.cs file…

that way the F7 key will now bounce back and forth between the XAML and the VM bound to it, lovely!

i know this is kinda controversial at first blush but think about it for a sec before jumping on condemnation…

at this point VM is the predominant paradigm for the “code behind” a view… the actual view class is likely to be empty.

admittedly, VM’s are not necessarily 1-to-1 with a View… they can be swapped out, many views to one model and driven by TDD… yet that is all still possible, we are merely talking about which .cs file the VM class definition is contained