I am creating a Windows 8.1 blank application in C#. The purpose of the application is to be a periodic table app which will be able to give users information about the chemical elements. However I have come into an issue where I haven't yet found a way to 'bind' data to a second page via a button click.
Below is the code I have been using to set the values on the MainPage.xaml.cs page to populate the TextBlocks on the 'ElementPage.xaml' depending on the button user clicks
  1. public class Elements  
  2.  {  
  3.  public string PeriodicElementName { getset; }  
  4.  public string ElementAtomicNumber { getset; }  
  5.   
  6.  public string ElementAtomicMass { getset; }  
  7.   
  8.  public string ElementDescription { getset; }  
  9.  public static Elements ShowElements(string Name, string AtomNumber, string AtomMass, string ElementDesc)  
  10.  {  
  11.  var ElementsInfo = new Elements()  
  12.  {  
  13.  PeriodicElementName = "Name: " + Name,  
  14.  ElementAtomicMass = "Atomic Mass: " + AtomMass,  
  15.  ElementAtomicNumber = "Atomic Number: " + AtomNumber,  
  16.  ElementDescription = "Description: " + ElementDesc  
  17.  };  
  18.  return ElementsInfo;  
  19.  }  
I.e. whenever the user clicks on the Lithium button they will be taken to a page which will then show information based off of the data I have set in the class in the behind code file.

I followed the answer described in the question http://stackoverflow.com/questions/24946575/passing-data-from-page-to-page-for-windows-phone-8-1
However, it did not work for me.
I have tried one method which did work which involved creating a public string variable named 'ElementChoice' in my 'MainPage.xaml.cs' file and then changing the variable value to the name of the element whenever that specific element's button was clicked.
  1. public static string ElementChoice;  

  1. private void btnLith_Click(object sender, RoutedEventArgs e)  
  2.  {  
  3.  ElementChoice = "Lithium";  
  4.   
  5.   
  6.   
  7.  }  
I would then have an if statement on the page I am navigating to named 'ElementPage.xaml.cs' saying
  1. if (ElementChoice=="Lithium")  
  2.  {  
  3.  DataContext = Elements.ShowElements("Lithium""3""6.94""This is Lithium");  
  4.  }  

However, I don't want to really have to create if statements for every single button.
So I was wondering if anybody could give me any guidance on how to pass the data from one page to another which could then bind the data depending on what button was clicked on the application?