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>