Answer the question
In order to leave comments, you need to log in
How to remove flickering CheckBoxes when updating data in wpf?
There is a ListBox with data. The data is updated, added about 1 time per second. The data at each update must be sorted by a certain parameter. All data rows have a CheckBox to indicate if they need to be updated further. In the case when the sorted data in the ListBox is updated, all CheckBox's are redrawn and the checkboxes marked with a checkbox flicker.
As follows:
<ListBox x:Name="lstbx" ItemsSource="{Binding Data.IDs}" SelectionMode="Single" SelectedItem="{Binding selectedID}"
HorizontalAlignment="Left" MinHeight="305" Margin="5" VerticalAlignment="Top" MinWidth="169" FontSize="10">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Margin="0,2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<CheckBox IsChecked="{Binding Enable}" VerticalAlignment="Center"/>
<TextBlock VerticalAlignment="Stretch" Grid.Column="1">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0}: {1}">
<Binding Path="Name"/>
<Binding Path="DiffCount"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
lstbx.Items.SortDescriptions.Clear();
lstbx.Items.SortDescriptions.Add(new System.ComponentModel.SortDescription("DiffCount", System.ComponentModel.ListSortDirection.Descending));
var idTemp = IDs.OrderByDescending(i => i.DiffCount).Select(i => i);
var newIDs = new Collection();
foreach (var id in idTemp)
newIDs.Add(id);
IDs = newIDs;
Answer the question
In order to leave comments, you need to log in
About sorting:
<ListBox Loaded="ListBoxOnLoadedHandler">
</ListBox>
private void ListBoxOnLoadedHandler(object sender, RoutedEventArgs e)
{
var listbox = sender as ListBox;
if (listbox == null)
return;
var view = CollectionViewSource.GetDefaultView(listbox.ItemsSource);
view.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question