I am creating dynamic UI based on some objects and the loading takes a lot of time because of the large number of items to be rendered. See below xml:-
<ScrollViewer Grid.Row="2" ZoomMode="Enabled" x:Name="scrollviewer"
VirtualizingStackPanel.VirtualizationMode="Recycling"
HorizontalScrollMode="Auto"
VerticalScrollMode="Auto"
VerticalSnapPointsType="None"
HorizontalSnapPointsType="None"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto"
MinZoomFactor="1" IsDoubleTapEnabled="True"
RenderTransformOrigin="0,0">
<Grid Background="#FFDDE6EB" x:Name="mygrid" VerticalAlignment="Center" HorizontalAlignment="Center">
</Grid>
</ScrollViewer>
The scrollviewer is inside a row with height as 10*.
Code to load items dynamically is below:-
public static Grid LoadGridWithItems(Model m)
{
var grid = new Grid();
grid.UseLayoutRounding = true;
grid.RowDefinitions.Clear();
grid.ColumnDefinitions.Clear();
int count = m.Rows;
for (int i = 0; i < count; i++)
{
grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) });
}
count = m.Columns;
for (int i = 0; i < count; i++)
{
grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(m.GetColumnWidth(i), GridUnitType.Star) });
}
foreach (Control control in m.Controls)
{
UIElement uicontrol=null;
if (control.Type != null)
{
switch (control.Type.ToLower())
{
case "textbox":
uicontrol=new TextBox();
break;
case "label":
uicontrol = new Label();;
break;
//bunch of other custom controls
}
}
grid.Children.Add(uicontrol);
}
return grid;
}
This generated grid is then added as a child to the "mygrid" defined in above xaml. Sometimes items are more than 5000 and it takes around 20-25 seconds to load. Any suggestions on how to implement this scenario in a better way?
Thanks!