Performance when loading list elements

Heiko 1,236 Reputation points
2024-10-06T15:08:00.5766667+00:00

I have about one hundred entries in a list. These are of data type DataA. A single entry within this list is of the data type DataB. DataB is derived from DataA. During debugging, I see in the output window that for all list elements of the data type DataA, all properties for the data type DataB are queried, although the grid, whose elements access the properties of DataB, is hidden. Although I can understand that it is necessary to query these properties and update the GUI elements with the values from DataB, I do not need to update the GUI elements if the grid surrounding them is hidden.

I used the StopWatch to measure the time it takes from the output of the constructor of the MainWindow to the call of Window_Loaded() and found that with the additional grid (for Player Controls) 30 to 40 percent more time is needed.

Is there a way to improve the performance?

public class DataA

{

// ...

public virtual Visibility => Visibility.Collapsed;

}

public class DataB : DataA // only for Player Controls

{

// ...

public override Visibility => Visibility.Visible;

}

<ItemsControl>

<ItemsControl.ItemTemplate>

<DataTemplate>

<Grid>

<TextBlock Foreground="{Binding ...}" Text="{Binding ...}" />

<TextBlock Foreground="{Binding ...}" Text="{Binding ...}" />

<TextBlock Foreground="{Binding ...}" Text="{Binding ...}" />

<TextBlock Foreground="{Binding ...}" Text="{Binding ...}" />

<!--...-->

<!--Player Controls-->

<Grid Visibility="{Binding PlayerVisibility}">

<TextBlock Text="{Binding ...}" />

<TextBlock Text="{Binding ...}" />

<TextBlock Text="{Binding ...}" />

<TextBlock Text="{Binding ...}" />

<Grid>

<Border BorderBrush="{Binding ...}">

<StackPanel>

<TextBlock Foreground="{Binding ...}" Text="{Binding ...}" />

<TextBlock Foreground="{Binding ...}" Text="{Binding ...}" />

<TextBlock Foreground="{Binding ...}" Text="{Binding ...}" />

</StackPanel>

</Border>

<!--...-->

</Grid>

</Grid>

</Grid>

</DataTemplate>

</ItemsControl.ItemTemplate>

</ItemsControl>

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,772 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,917 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.