开发者

WPF Listview flickering problem

开发者 https://www.devze.com 2023-03-30 02:30 出处:网络
I am using a thread for reading the file and make a array of objects from the data read.A seperate thread for filtering records based on some filters is being used.

I am using a thread for reading the file and make a array of objects from the data read.A seperate thread for filtering records based on some filters is being used. I am using listview to show data for dataset I get as per above.

While laoding a file everthing seems good but when I search,the problem exists.

while searching when I apply filters for the 1st time, everything is okay. Now again when I apply filters, data of the previous search is show for 1 sec(kind of flicker) and then the new data according to current filter is rendered. I am using dispatcher for updating UI. Before I bind any data, I try to clear ListView ItemSource by setting it to null

XAML code i am using is : {

                 <ListView Name="listView1" 
                  Grid.Row="0" 
                  ItemsSource= "{Binding ElementName=Window1, Path=Entries}" 
                  AllowDrop="True"
                  SelectionChanged="listView1_SelectionChanged" 
                  Drop="listView1_Drop">
                  <ListView.View>
                    <GridView x:Name="GridView1" >
                        <GridViewColumn Header="Item" DisplayMemberB开发者_如何学JAVAinding="{Binding Item}"  />
                        <GridViewColumn Header="TimeStamp" DisplayMemberBinding="{Binding TimeStamp}"/>
                        <GridViewColumn Header="">
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <Image Source="{Binding Image}" Width="16" Height="16" VerticalAlignment="Top" HorizontalAlignment="Left"/>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn Header="Level" DisplayMemberBinding="{Binding Level}"/>
                        <GridViewColumn Header="Class" DisplayMemberBinding="{Binding Class}"/>
                        <GridViewColumn Header="Message" DisplayMemberBinding="{Binding Message1}" Width="250" />
                    </GridView>
                </ListView.View>
            </ListView> 

}

Code Behind is :

private void ClearListView()
{
    UpdateList update = new UpdateList(UpdateListData);
    List<LogEntry> searcheddata = new List<LogEntry>();
    searcheddata = null;

    listView1.ItemsSource = null;
    listView1.Items.Clear();
    listView1.Items.Refresh();
    pdDispatcher.BeginInvoke(update, DispatcherPriority.Render, searcheddata);
}

psdispatcher is the dispatcher used to update the UI & searchdata is function to assign datasource to listview

0

精彩评论

暂无评论...
验证码 换一张
取 消