Quantcast
Channel: VBForums - WPF, WCF, WF
Viewing all articles
Browse latest Browse all 256

Binding to listbox (with Richtextbox) is slow

$
0
0
Well, I just got less that 10 items and I can see the listbox populating it, looks like crawling when it is being populated. Here is my DataTemplate:
Code:

<DataTemplate x:Key="exerciseTemplate">
            <Border Name="border" BorderBrush="Blue" BorderThickness="1" Padding="5" Margin="5">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Name="col1" Width="*" />
                    </Grid.ColumnDefinitions>

                    <extToolkit:RichTextBox             
                                Text="{Binding Path=Exercise, Mode=TwoWay}"
                                Focusable="False"
                                IsReadOnly="True"
                                Width="Auto"
                                Grid.Row="0"
                                Grid.Column="0"                             
                                VerticalAlignment="Stretch" >
                        <FlowDocument PageWidth="1000"></FlowDocument>
                    </extToolkit:RichTextBox>

                </Grid>
            </Border>
        </DataTemplate>

Here's be listbox definition:
Code:

<ListBox HorizontalContentAlignment="Stretch" ItemTemplate="{StaticResource exerciseTemplate}" Margin="6" Name="listBoxExercises" SelectionMode="Single" SnapsToDevicePixels="False" VerticalContentAlignment="Stretch"  VirtualizingStackPanel.VirtualizationMode="Recycling" />
And here's how I am populating it.
Code:

private void PopulateExercises(int topicID)
        {           
            db.ConnectionString = Settings.ConnectionString;

            OleDbCommand cmd = new OleDbCommand("SELECT * FROM Exercises WHERE TopicID=" + topicID, db);
            db.Open();

            OleDbDataReader reader = cmd.ExecuteReader();
           
            exercises = new ExercisesList();

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    exercises.Add(new cExercise(reader.GetInt32(0), reader.GetInt32(1), reader.GetString(2), reader.GetValue(3).ToString(), reader.GetBoolean(4)));
                }
            }
            reader.Close();
            db.Close();

           
            listBoxExercises.ItemsSource = exercises;
        }

Can you guys recommend on some improvements I can make? What I've noticed it, even after the ItemsSource is already set, when I click on the TabPage where the Listbox is contained and I clicked on that TabPage, I can it being populated one at a time.

Viewing all articles
Browse latest Browse all 256

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>