title: How to structure and edit images that are in an xaml grid and adjust them in C#
body: <p>I've been searching around for methods to manage grided images through c sharp and xaml. So far what I've read is to use xaml and then edit it with c sharp instead of creating everything in c sharp for xaml to use. (<a href="https://stackoverflow.com/questions/14467762/how-to-display-image-in-a-grid-using-c-sharp-for-wp8">how to display image in a grid using C# for WP8?</a>)
  It's quiet possible what I'm looking for is described here, and I'm missing/not-understanding it.</p>
  
  <p>My first rather blind attempt at this was to just create a class and give it factors in c sharp to then use and implement on the created images in xaml.</p>
  
  <p>What I'm wondering is if there is a better way to "sync" the two. For example if the user tapped one of the images Is there an easy way to tell which one they tapped as far as the myGridSpace [0] or [1].</p>
  
  <p>So far the way I've been determining is calling a method that searches for matching coordinates to what I give it I.E: FindGridWithMethod(0,0,0,0); public int FindGridWithMethod(int Left, int Top, int Right, int Bottom)
  //For Loops until found return either 0 or 1
  The trouble is, I still have to manually type this into each image_tapped method, it feels disjointed and I'm looking for better unity.</p>
  
  <p>I've written up an example, my main project has a grid of at <strong>least</strong> 4 x 4.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.IO;
  using System.Linq;
  using System.Runtime.InteropServices.WindowsRuntime;
  using Windows.Foundation;
  using Windows.Foundation.Collections;
  using Windows.UI.Xaml;
  using Windows.UI.Xaml.Controls;
  using Windows.UI.Xaml.Controls.Primitives;
  using Windows.UI.Xaml.Data;
  using Windows.UI.Xaml.Input;
  using Windows.UI.Xaml.Media;
  using Windows.UI.Xaml.Navigation;
  
  // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=391641
  
  namespace App1
  {
      /// &lt;summary&gt;
      /// An empty page that can be used on its own or navigated to within a Frame.
      /// &lt;/summary&gt;
      public sealed partial class MainPage : Page
      {
          public class GridSpaces
          {
              //Margin
              public int fromLeft;
              public int fromRight;
              public int fromTop;
              public int fromBottom;
              //Who is in this square
              public String occupiedBy;
              //The image for the grid space
              public String sourceImage;
  
  
          }
  GridSpaces[] myGridSpaces = new GridSpaces[2];
          public MainPage()
          {
              this.InitializeComponent();
              for (int i = 0; i &lt; 2; i++)
          {
  
  
              myGridSpaces[i] = new GridSpaces()
  
              {
                  OccupiedBy = "Nothing",
  //GreenCellBorder is a string containing the file source of the image
                  sourceImage = GreenCellBorder
  //Insert Margin Variables Here
  
              };
  
          }
              this.NavigationCacheMode = NavigationCacheMode.Required;
          }
  
          /// &lt;summary&gt;
          /// Invoked when this page is about to be displayed in a Frame.
          /// &lt;/summary&gt;
          /// &lt;param name="e"&gt;Event data that describes how this page was reached.
          /// This parameter is typically used to configure the page.&lt;/param&gt;
          protected override void OnNavigatedTo(NavigationEventArgs e)
          {
              // TODO: Prepare page for display here.
  
              // TODO: If your application contains multiple pages, ensure that you are
              // handling the hardware Back button by registering for the
              // Windows.Phone.UI.Input.HardwareButtons.BackPressed event.
              // If you are using the NavigationHelper provided by some templates,
              // this event is handled for you.
          }
  
          private void Image_Tapped(object sender, TappedRoutedEventArgs e)
          {
  
          }
  
          private void Image_Tapped_1(object sender, TappedRoutedEventArgs e)
          {
  
          }
      }
  }
  
  
  &lt;Page
      x:Class="App1.MainPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="using:App1"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      mc:Ignorable="d"
      Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"&gt;
  
      &lt;Grid&gt;
          &lt;Image HorizontalAlignment="Left" Height="100" Margin="43,72,0,0" VerticalAlignment="Top" Width="100" Source="Assets/First Action.png" Tapped="Image_Tapped"/&gt;
          &lt;Image HorizontalAlignment="Left" Height="100" Margin="159,72,0,0" VerticalAlignment="Top" Width="100" Source="Assets/Second Action.png" Tapped="Image_Tapped_1"/&gt;
  
      &lt;/Grid&gt;
  &lt;/Page&gt;
  </code></pre>