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.