I am a new developer on Windows Phone 8.1, I'm trying to reach a specific ListView element from the ListView collection and be able to color it or the TextBock color inside it, but I canβt get to the item or reach any of the elements inside the ListView, please see my code below:
protected async override void OnNavigatedTo(NavigationEventArgs e) { SQLiteRT db1 = new SQLiteRT(); var db_connection = await db1.Connection("MyDB.sqlite"); List<MyTBL> t_list = db1.GetTable("SELECT * FROM MyTBL LIMIT 4 ORDER BY RANDOM() ;"); db_connection.Close(); LV_Options.ItemsSource = t_list; } // my List View called LV_Options private void LV_Options_SelectionChanged(object sender, SelectionChangedEventArgs e) { ListView lv1 = sender as ListView; if (lv1 == null) return; MyTBL wrd = lv1.SelectedItem as MyTBL; if (wrd == null) return; TextBlock tb = lv1.FindName("TB_AMean1") as TextBlock; tb.FontSize = 17; // here I got debug error (it not worked !!!!!!!) var item = LV_Options.Items.ElementAt(3); // this seems not work also !!!! item.BackColor = Color.LightSteelBlue; }
As you can see above, I tried to reach a specific LV_Options.Items.ElementAt (3) element, but it does not work! I also tried to get to the TextBlock from the selected View List element, but also does not work!
(Updated) XAML Code:
<StackPanel Grid.Row="0" Margin="19,0,0,0"> <TextBlock Name="TB_Rslt" Text="Here result of your answer" Style="{ThemeResource TitleTextBlockStyle}" Margin="0,12,0,0"/> <TextBlock Text="page title" Margin="0,-6.5,0,26.5" Style="{ThemeResource HeaderTextBlockStyle}" CharacterSpacing="{ThemeResource PivotHeaderItemCharacterSpacing}"/> </StackPanel> <Grid Grid.Row="1" x:Name="ContentRoot" Margin="19,10,19,15"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <TextBlock Name="TB_Question" Text="Choose Answer " Margin="0,0,25,0" HorizontalAlignment="Right" FontWeight="Bold" FontSize="22" FontFamily="Verdana" RenderTransformOrigin="0.5,0.5" /> <TextBlock Name="TB_EnWord" Text="" Margin="90,0,15,0" HorizontalAlignment="Left" FontWeight="Bold" FontSize="22" FontFamily="Verdana" RenderTransformOrigin="0.5,0.5" TextAlignment="Right" /> <StackPanel Grid.Row="1" Margin="5,22,0,0"> <ListView Name="LV_Options" SelectionChanged="LV_Options_SelectionChanged"> <ListView.ItemTemplate> <DataTemplate> <Grid Margin="6"> <StackPanel VerticalAlignment="Top" Margin="10,0,0,0"> <TextBlock Name="TB_AMean1" Text="{Binding AMean1}" TextWrapping="Wrap"/> </StackPanel> </Grid> </DataTemplate> </ListView.ItemTemplate> </ListView> </StackPanel> <Button Name="Btn_Answer" Content="Ansewr" HorizontalAlignment="Left" Grid.Row="1" VerticalAlignment="Bottom" Click="Btn_Answer_Click"/>
My application is a quiz application that offers 4 options / options as answers to each question, and when the user selects the correct answer, I want to highlight the true answer (true choice), turn its background green, and if the user selects the wrong answer / parameter. I want to make the background of this answer (specific list item) red.
Any help please?