2014-05-14 41 views
0

我发展我的Windows Phone上的第一个应用,我有cotains 3元,2元是图像和textblock.Now我能够填充LongListSelector项目的LongListSelector,但我需要删除一些项目,只要它不是必需的在列表中删除Longlistselector中的选定元素?

根据我们是否点击图片来删除项目。我的代码如图所示。

<phone:LongListSelector x:Name="MainLongListSelector" DataContext="{Binding listData}" IsGroupingEnabled="False" > 
      <phone:LongListSelector.ItemTemplate> 
       <DataTemplate> 
        <StackPanel Orientation="Horizontal" Grid.Column="0"> 
         <Image Name="condition" Source="{Binding Imagetype}" Height="100" /> 
         <StackPanel Grid.Column="1"> 
          <TextBlock Text="{Binding Country}" TextWrapping='Wrap' Style="{StaticResource PhoneTextExtraLargeStyle}" FontSize="30"/> 
          <TextBlock Text="{Binding Temp}" TextWrapping="Wrap" 
             Style="{StaticResource PhoneTextExtraLargeStyle}" 
             FontSize="30" 
             ></TextBlock> 
         </StackPanel> 
         <StackPanel HorizontalAlignment="Right" Grid.Column="2"> 
          <Image Name="Button" Source="{Binding Remove}" Height="100" Stretch="UniformToFill" HorizontalAlignment="Right"/> 
         </StackPanel> 
        </StackPanel> 
       </DataTemplate> 
      </phone:LongListSelector.ItemTemplate> 
     </phone:LongListSelector> 

我需要从每当用户点击图片与NAME =按钮列表中删除整个元素,请帮我在做这个,因为我非常新的这个领域。

回答

0

添加SelectionChanged事件并执行下面的操作来获取选定的项目。

private void MainLongListSelector_SelectionChanged(object sender, SelectionChangedEventArgs e) 
{ 
    if (e.AddedItems.Count > 0) 
    { 
     YourListItemObject item = e.AddedItems[0] as YourListItemObject; 
     YourMainList.Remove(item); 
    } 

} 

编辑:

private void Button_Tap(object sender, System.Windows.Input.GestureEventArgs e) 
{ 
    var element = (FrameworkElement)sender; 
    YourListItemObject data = (YourListItemObject)element.DataContext; 
    YourMainList.Remove(data); 
} 
+0

@sajeetharan ....但将允许我以消除的基础元素的点击image.I想,只有当用户点击删除元素该图像这是listselector – dhee

+0

@dhee内肯定会,如果没有相同的代码添加到您的按钮点击,让我知道,如果它不工作 – Sajeetharan

+0

@Sajeetharan ......它的工作,但不是在路上,我想,一个小的帮助,我需要的元素才能被删除,只有当我点击名称=按钮的图像,但在这种情况下,它的开始每次点击任何元素时都会被删除,请帮助我。提前致谢。 – dhee