마우스 클릭 된 ImageButton과 관련된 클래스 데이터를 얻으려고 시도하고 있습니다. 어떤 ImageButton이 Scollviewer로 싸여진 WrapPanel 내에 위치하고 수많은 다른 ImageButton으로 채워져 있습니다. 문제는 "((PlanetClass) (fe))"를 선택한 ImageButton의 인스턴스를 볼 수는 있지만 클래스 인스턴스의 기본 데이터 "((PlanetClass) (fe)) .Content"의 가시성을 가질 수는 없다는 것입니다. 클래스의 필드 데이터에 액세스 할 수 있습니다. 아래의 예는 제 의도를 보여줍니다.WrapPanel 내에있는 Mouse Clicked ImageButton의 클래스 필드 데이터의 가시성
이 문제 (WrapPanel (ScrollViewer에서 래핑 됨) -> ImageButton-> FrameworkElement -> 인스턴스의 단추 -> 필드 데이터)가 올바르게 접근합니까? 그렇지 않은 경우 ImageButton 인스턴스와 인스턴스의 관련 데이터에 액세스하는 가장 좋은 방법은 무엇입니까? 누구든지 올바른 방향으로 나를 가리켜 주시겠습니까?
// 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; }
}
}