Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

How can i display controls faster which is added run time?

$
0
0

Hi,

I have a one form and I try to display data in DataGrid control with 100,000 rows & 10 columns and filling grid from DataTable. It works fine. I try to display data in TextBlock and adding TextBlock in StackPanel. But it takes to much time to display while DataGrid is faster. What kind of improvement I required in my code.

Here code is displayed.

///// Designing<Window x:Class="ToolBarApp.frmSearch"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    WindowStartupLocation="CenterScreen"
    Title="frmSearch" Height="500" Width="500" ><Grid><ScrollViewer><StackPanel Name="ctl_Display"></StackPanel></ScrollViewer></Grid></Window>

//// Constructor

public frmSearch(bool AddToGrid, DataTable _dt)
        {
            InitializeComponent();

            if (AddToGrid)
            {
                DataGrid _dg = new DataGrid();
                _dg.Height = 450;
                _dg.Width = 450;
                _dg.AutoGenerateColumns = true;
                _dg.ItemsSource = _dt.DefaultView;
                ctl_Display.Children.Add(_dg);
            }
            else
            {
                TextBlock _TextBlock;

                foreach (DataRow _DR in _dt.Rows)
                {

                    _TextBlock = new TextBlock();
                    _TextBlock.Margin = new Thickness(0);
                    _TextBlock.FontSize = 14;
                    _TextBlock.Foreground = Brushes.White;
                    _TextBlock.Text = _DR["Item_Name"].ToString();
                    ctl_Display.Children.Add(_TextBlock);
                }
            }
        }



Viewing all articles
Browse latest Browse all 18858

Trending Articles



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