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 associated data? Can anyone please point me in the right direction?
// WPF EventHandler at the container level:
Expand|Select|Wrap|Line Numbers
- <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; }
- }
- }