Help sort the data in listbox.
Find the TextBlock Text element of which will be equal to the selected Combobox item, then delete the extra ListBoxItems and leave only those that contain the selected Combobox item
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { string text = (sender as ComboBox).SelectedItem as string; foreach (var realmBlock in FindVisualChildren<TextBlock>(this)) { if (realmBlock.Text == text) { ArrayList arList = new ArrayList(); foreach (object obj in charList.Items) { arList.Add(obj); } //arList.Sort(); charList.Items.Clear(); foreach (object obj in arList) { charList.Items.Add(obj); } } } } Do not quite understand how to do it
Listbox code
<ListBox x:Name="charList" Width="326" HorizontalAlignment="Left" Background="{x:Null}" BorderBrush="Transparent" ItemContainerStyle="{StaticResource ListBoxItem}" ItemTemplate="{DynamicResource CharTemplate}" ItemsSource="{Binding}" SelectedIndex="0" Padding="0,5,0,0" VirtualizingPanel.ScrollUnit="Pixel"> <ListBox.Resources> <DataTemplate x:Key="CharTemplate"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="125" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <Image x:Name="listCharPortait" Width="80" Height="50" Source="{Binding ImageLink}" Stretch="Fill" /> <StackPanel Grid.Column="1" MaxWidth="174" MaxHeight="100" Margin="-5,25,0,25" HorizontalAlignment="Left" VerticalAlignment="Top"> <StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Orientation="Horizontal" TextBlock.FontWeight="Bold"> <TextBlock x:Name="nameBlock" Text="{Binding Realms}" TextTrimming="CharacterEllipsis" TextWrapping="Wrap"> <TextBlock.Foreground> <SolidColorBrush Opacity="0.5" Color="#FF959595" /> </TextBlock.Foreground> </TextBlock> </StackPanel> <StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Orientation="Horizontal"> <TextBlock FontFamily="/Launcher;component/Resources/#Blizzard" FontSize="14" Foreground="White" Text="{Binding Title, FallbackValue=Title}" TextTrimming="CharacterEllipsis" TextWrapping="Wrap" /> </StackPanel> </StackPanel> </Grid> </DataTemplate> </ListBox.Resources> </ListBox>