I am attempting to obtain class-data associated with a mouse-clicked ImageButton; which ImageButton is located within a Scollviewer wrapped WrapPanel and filled with numerous other ImageButtons. The problem is that although I can see the instance of the ImageButton selected "((PlanetClass)(fe))", and have visibility of the class instance's underlying data "((PlanetClass)(fe)).Content", I am unable to access any of the class's field data. The example below illustrates my intention.
Am I approaching this problem correctly (WrapPanel (wrapped in ScrollViewer)-> ImageButton-> FrameworkElement -> Instance of the Button -> Field Data)? If not, what would the best way be to access the ImageButton instance and the instance's associated data? Can anyone please point me in the right direction?
// WPF EventHandler at the container level:
<ScrollViewer ButtonBase.Click="SolarSystem_Click">
// Handles the ImageButton mouseClick event within the ScrollViewer wrapping the WrapPanel.
private void SolarSystem_Click(Object sender, RoutedEventArgs e)
{
FrameworkElement fe = e.OriginalSource as FrameworkElement;
SelectedPlanet PlanetSelected = new SelectedPlanet(fe);
MessageBox.Show(PlanetSelected.PlanetName);
}
// Used to initiate instance of ImageButton to access field data.
public SelectedPlanet(FrameworkElement fe)
{
return ((PlanetClass)(fe));
}
// Class Data
public class PlanetClass
{
string planetName;
public PlanetClass(string planetName)
{
PlanetName = planetName;
}
public string PlanetName
{
set { planetName = value; }
get { return planetName; }
}
}