2013-02-03 2 views
0

windows phone의 목록 상자에 각 항목의 확인란을 this tutorial (옵션 2)의 도움으로 추가했습니다. 전에 ListBox에 대한 SelectionChanged 이벤트가 이미있었습니다. 사용자가 확인란을 선택했을 때 이벤트 발생을 방지하려면 어떻게해야합니까? SelectionChanged 이벤트는 체크 상자가 아닌 목록 상자에서 텍스트 상자를 눌렀을 때만 실행됩니다.selectChanged 이벤트를 트리거하지 않고 목록 상자 내에서 액세스 제어

 private void CheckBox_Checked(object sender, RoutedEventArgs e) 
    { 
     ListBoxItem checedItem = this.toDoItemsListBox.ItemContainerGenerator.ContainerFromItem((sender as CheckBox).DataContext) as ListBoxItem; 
     if (checedItem != null) 
     { 
      checedItem.IsSelected = true; 
     } 
    } 

    private void CheckBox_Unchecked(object sender, RoutedEventArgs e) 
    { 
     ListBoxItem checedItem = this.toDoItemsListBox.ItemContainerGenerator.ContainerFromItem((sender as CheckBox).DataContext) as ListBoxItem; 
     if (checedItem != null) 
     { 
      checedItem.IsSelected = false; 
     } 
    } 

이 또한 내가 확인란을 선택하면에서 selectionChanged 이벤트는 제기 언급해야 :이 내 체크 이벤트입니다

   <ListBox x:Name="toDoItemsListBox" ItemsSource="{Binding Source={StaticResource cvs}}" Grid.Row="1" Margin="12, 0, 12, 0" Width="440" SelectionChanged="goToNavigation" IsSynchronizedWithCurrentItem="False"> 
        <ListBox.ItemTemplate> 
         <DataTemplate> 
          <StackPanel Orientation="Horizontal" > 
          <CheckBox IsChecked="{Binding IsFavorite}" Height="48" Width="48" Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked" Style="{StaticResource CheckBoxStyle1}"/> 
          <StackPanel Orientation="Vertical"> 
           <TextBlock Text="{Binding Shortcut}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}" /> 
           <TextBlock Text="{Binding BuildingName}" TextWrapping="Wrap" Style="{StaticResource PhoneTextSubtleStyle}" /> 
          </StackPanel> 
         </StackPanel> 
        </DataTemplate> 
        </ListBox.ItemTemplate> 
       </ListBox> 

:

내 목록 상자를 이잖아. 선택을 취소하지 않았을 때.

답변

0

선택 변경 이벤트없이 작동 시켰습니다.

 private void StackPanel_Tap(object sender, System.Windows.Input.GestureEventArgs e) 
    { 
     // Save current POI. 
     Object object = (sender as StackPanel).DataContext as Object; 
    ...} 
:
      <StackPanel Orientation="Vertical" Tap="StackPanel_Tap"> 
           <TextBlock Text="{Binding Shortcut}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}" /> 
           <TextBlock Text="{Binding BuildingName}" TextWrapping="Wrap" Style="{StaticResource PhoneTextSubtleStyle}" /> 
          </StackPanel> 

및 코드에서

내가 내을 listitem을 얻을 뒤에 : 다른 방법으로 나는 탭 이벤트를 사용