Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8608307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:34:42+00:00 2026-06-12T03:34:42+00:00

I am thinking about converting one of my apps over to WPF, and one

  • 0

I am thinking about converting one of my apps over to WPF, and one of my main concerns was the performance of the DataGrid control (my user’s computers are outdated XP machines with no dedicated graphics). I experimented with a few thousand rows and scrolling performance was horrible.

I was wondering if there is a way to set the datagrid cell’s content to a custom class that derives from FrameworkElement?

Here is a sample class that appears to have much better performance when put in a virtualizing stackpanel:

public class LiteTextBlock : FrameworkElement
{
    private Size _mySize;
    private string _myText;
    private double totalWidth;
    private GlyphTypeface _typeface;
    private int _fontSize;
    private GlyphRun _run;

    public LiteTextBlock(Size mySize, string myText, GlyphTypeface typeface, int fontSize)
    {
        _mySize = mySize;
        this.Width = _mySize.Width;
        this.Height = _mySize.Height;
        _myText = myText + " additional information";
        _typeface = typeface;
        _fontSize = fontSize;
    }

    protected override void OnRender(DrawingContext drawingContext)
    {
        if (_run == null)
        {
            totalWidth = 0;

            ushort[] glyphIndexes = new ushort[_myText.Length];
            double[] advanceWidths = new double[_myText.Length];

            for (int i = 0; i < _myText.Length; i++)
            {
                ushort glyphIndex = _typeface.CharacterToGlyphMap[_myText[i]];
                double width = _typeface.AdvanceWidths[glyphIndex] * _fontSize;

                if (totalWidth + width >= _mySize.Width - 10)
                {
                    Array.Resize(ref glyphIndexes, i);
                    Array.Resize(ref advanceWidths, i);
                    break;
                }

                glyphIndexes[i] = glyphIndex;
                advanceWidths[i] = width;
                totalWidth += width;
            }

            Point origin = new Point(5, 0);

            _run = new GlyphRun(_typeface, 0, false, _fontSize, glyphIndexes
                , origin, advanceWidths, null, null, null, null, null, null);
        }

        drawingContext.DrawGlyphRun(Brushes.Black, _run);
    }
}

Can anyone show me if this is possible?

Disclaimer: I have already tried using lighter-weight controls such as the ListView, but performance was still poor.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:34:43+00:00Added an answer on June 12, 2026 at 3:34 am

    Yes, there is a way.

    You need to implement your custom DataGridColumn and override its GenerateElement method and you need to handle DataGrid.AutoGeneratingColumn event to set your custom DataGridColumn to DataGrid.

    Here is a sample for custom DataGridColumn:

    public class DataGridLiteTextColumn : DataGridColumn
    {
        private readonly PropertyDescriptor property;
    
        private readonly GlyphTypeface glyphTypeface = new GlyphTypeface(new Uri("file:///C:\\WINDOWS\\Fonts\\Arial.ttf"));
    
        public DataGridLiteTextColumn(PropertyDescriptor property)
        {
            this.property = property;
        }
    
        protected override FrameworkElement GenerateElement(DataGridCell cell, object dataItem)
        {
            var value = property.GetValue(dataItem);
            return new LiteTextBlock(new Size(100, 20), value != null ? value.ToString() : string.Empty, this.glyphTypeface, 10);
        }
    
        protected override FrameworkElement GenerateEditingElement(DataGridCell cell, object dataItem)
        {
            throw new NotImplementedException();
        }
    }
    

    Here is a handler for DataGrid.AutoGeneratingColumn event:

    private void OnAutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
    {
        e.Column = new DataGridLiteTextColumn((PropertyDescriptor)e.PropertyDescriptor);
    }
    

    This code will work for displaying values, although LiteTextBlock constructor size parameters are probably not set to appropriate values. To edit values you must also implement GenerateEditingElement method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am thinking about converting a PDF document into a long scrolling HTML doc
I have a PHP/MySQL site I'm thinking about converting into a HTML5/JavaScript that could
How does one go about thinking about designing digital logic chips in an abstract
One of the things I’ve been thinking about a lot off and on is
Thinking about avoiding code replication, I got a question that catches me every time
Thinking about if we modify the definition of Hamiltonian path as we need to
Im thinking about to use a DB for my logs instead of a normal
Im thinking about building an application on our website to track order places through
Been thinking about this for hours now. Im building a simple slideshow application, where
Just thinking about the best way to build an Order form that would (from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.