Image tap event in ListView windows store app

匿名 (未验证) 提交于 2019-12-03 02:35:01

问题:

I am developing my first application in windows 8 for WinRT. my application is implemented with one listview and listview contains two image control i want to add tap event on image control when image tapped then that image's visibility gets Collapsed and another image's visibility gets visible. My code=

 <ListView Name="display" ItemsSource="{Binding}"  >    <ListView.ItemsPanel>       <ItemsPanelTemplate>          <StackPanel  Orientation="Horizontal" />      </ItemsPanelTemplate>     </ListView.ItemsPanel>      <ListView.ItemTemplate>          <DataTemplate>             <StackPanel Orientation="Vertical">               <Image Source="{Binding  Path=Image}" />               <TextBlock Text="{Binding Image_Name}" FontSize="25" Foreground="Gray" Margin="180,0,0,0"  />               <TextBlock Text="{Binding Description}" FontSize="20" Foreground="Gray" Margin="140,0,0,0" />                <Image x:Name="add" Source="{Binding  Path=Image1}" Height="30" Opacity="0.7" Tapped="add_Tapped" />                <Image x:Name="sub" Source="{Binding  Path=Image2}" Height="30" Opacity="0.7" Visibility="Collapsed" />             </StackPanel>           </DataTemplate>          </ListView.ItemTemplate>  </ListView> 

I have used this code but it works for all the add image control not for particular item. i want to do it for only particular item which is pressed by user.

 private void SearchVisualTree(DependencyObject targetElement)     {         var count = VisualTreeHelper.GetChildrenCount(targetElement);         if (count == 0)             return;        for (int i = 0; i < count; i++)         {             var child = VisualTreeHelper.GetChild(targetElement, i);             if (child is Image)             {                 Image myItems = (Image)child;                 if (myItems.Name == "add")                 {                     myItems.Visibility = Visibility.Collapsed;                    return;                 }             }             else             {                 SearchVisualTree(child);             }         }    }      private void add_Tapped(object sender, TappedRoutedEventArgs e)     {         SearchVisualTree(this.display);  //display is a listview name      } 

I want to create code for when add image tapped then add image's visibilty gets Collapsed and the another sub image's visibility gets visible for particular that item. how can I create it please help me. and another thing i am new to windows 8 development i want to use web api to this app with Json service. which tutorial can help me please suggest me.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!