アプリの1つをWPFに変換することを考えていますが、主な懸念事項の1つは、DataGrid
コントロールのパフォーマンスでした(ユーザーのコンピューターは、専用のグラフィックを備えていない古いXPマシンです)。私は数千行を試しましたが、スクロールのパフォーマンスはひどいものでした。
FrameworkElement
データグリッドセルのコンテンツを、 ?から派生したカスタムクラスに設定する方法があるかどうか疑問に思いました。
仮想化スタックパネルに配置すると、パフォーマンスが大幅に向上するように見えるサンプルクラスを次に示します。
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);
}
}
これが可能かどうか誰かに見せてもらえますか?
免責事項:私はすでに、などの軽量のコントロールを使用しようとしましたListView
が、パフォーマンスはまだ劣っていました。