Windows Phone 8을 개발 중이며 단일 선택 목록 상자와이 방법이 있습니다.
private void locationsList_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
ARLocation item = (ARLocation)locationsList.SelectedItem;
NavigationService.Navigate(new Uri("/Views/MapPage.xaml", UriKind.Relative));
locationsList.SelectedItem = null;
}
내가 할 locationsList.SelectedItem = null;
때 SelectionChanged
이벤트가 다시 트리거됩니다.
SelectedItem을 지울 때 이벤트가 트리거되지 않도록하려면 어떻게해야합니까?
이벤트 구독 취소를 원하지 않는 한 피할 수 없습니다. 선택한 항목을 변경하는 것이므로 이벤트가 시작됩니다.
이러한 작업을 시도해 볼 수 있습니다. 구독을 취소 한 다음 이벤트를 구독하세요.
locationsList.SelectioChanged -= locationsList_SelectionChanged;
locationsList.SelectedItem = null;
locationsList.SelectioChanged += locationsList_SelectionChanged;
그러나이 경우 검사를 수행하는 것이 더 쉬울 수 있습니다.
private void locationsList_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
if ((sender as ListBox).SelectedItem != null)
{
ARLocation item = (ARLocation)locationsList.SelectedItem;
NavigationService.Navigate(new Uri("/Views/MapPage.xaml", UriKind.Relative));
locationsList.SelectedItem = null;
}
}
또는 이벤트를 건너 뛰어야 함을 알리기 위해 부울을 제공 할 수 있습니다.
private bool SkipEvent = false;
private void locationsList_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
if (SkipEvent) return;
ARLocation item = (ARLocation)locationsList.SelectedItem;
NavigationService.Navigate(new Uri("/Views/MapPage.xaml", UriKind.Relative));
// Skip block:
try
{
SkipEvent = true;
locationsList.SelectedItem = null;
}
finally { SkipEvent = false; }
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다