Laden...

WPF-DataGrid mit einem Scrollviewer komplett ausdrucken, nicht nur sichtbarer Bereich

Letzter Beitrag vor 8 Jahren 5 Posts 3.411 Views
WPF-DataGrid mit einem Scrollviewer komplett ausdrucken, nicht nur sichtbarer Bereich

Ich habe in WPF ein DataGrid, das in einem ScrollViewer läuft.
ich möchte dieses DataGrid ausdrucken und zwar die gesamte Sicht und nicht bloss die Sicht im ScrollViewer.
Ich weis nicht, ob ein DataGrid so vollständig direkt ausgedruckt werden kann oder ob man in diesem Fall die einzelnen Cellen zum Beispiel in ein FixDocument schreiben muss.
Hat jemand Erfahrung mit dem Drucken von DataGrid's.
Besten Dank für eure Hinweise...

Ich denke, dass dir nicht anderse überigbleit als ein FixedDocument zu erstelle, da ein Datagrid keine Druckerfunktionen bereitstellt. Möchtest du noch eine Druckvoschau must du mit IDocumentPaginatorSource arbeiten.

Wen nötig kann ich eine eigene Basis-Klasse zur vwerfügung stellen:

Gruss Alex

Danke dir für die schnelle Antwort.
gerne würde ich deine Basisklasse anschauen. Komme ich so sicher schneller ans Ziel... 🙂

Zuerst benötigt man die PrintBasis-Klasse



sing System;
using System.Collections.Generic;
using System.IO;
using System.IO.Packaging;
using System.Printing;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Xps;
using System.Windows.Xps.Packaging;
using System.Windows.Xps.Serialization;
using sd = System.Drawing;

namespace js.WPFbase.Printing
{
    public abstract class PrintBase 
    {

        #region Const

        protected const double _LEFT_MARGIN = 60;
        protected const double _TOP_MARGIN = 80;

        protected const string _FONT_NAME = "Tahoma";
        protected const string _FORMAT_NUMBRE = "#,##0.00";
        protected const string _FORMAT_DATE = "dd, MM, yyyy";
        protected const double _ROW_HEIGHT = 7.5D;

        protected const double _TITLE_SPACE1 = 60D;
        protected const double _TITLE_SPACE = 40D;
        protected const double _HEADER_SPACE = 25D;
        protected const double _ROW_SPACE = 17D;

        protected const int _MAX_ROWS_PER_SHEET = 50;

        private const string _XPS_FILE_NAME = "C:\\temp\\tmp.xps";

        #endregion

        #region PrintFolder

        private PrintDialog _printDialog;
        private PageOrientation _pageOrientation = PageOrientation.Portrait;
        private PageMediaSizeName _pageSize = PageMediaSizeName.ISOA4;

        #endregion

        #region DocumentFolder

        private FixedDocument _fixedDoc;

        protected Dictionary<int, Canvas> _contentDictionary;


        #endregion

        #region PrivateFolder

        private int _pageCounter = 0;
        private double _top;
        private double _left;

        #endregion

        public PrintBase()
        {
            _contentDictionary = new Dictionary<int, Canvas>();
            InitPrinter(false);
        }

        #region Document

        public FixedDocument FixedDoc { get { return _fixedDoc; } }

        #endregion

        #region Protected

        protected enum TextSize {Default, Small, Midel, Big }

        protected void AddPages()
        {
            _pageCounter++;
            _contentDictionary.Add(_pageCounter, new Canvas());

        }

        protected PageMediaSizeName PageSize
        {
            get { return _pageSize; }
            set
            {
                _pageSize = value;
                _printDialog.PrintTicket.PageMediaSize = new PageMediaSize(value);
            }
        }

        protected PageOrientation PageOrientation
        {
            get { return _pageOrientation; }
            set
            {
                _pageOrientation = value;
                _printDialog.PrintTicket.PageOrientation = value;
            }
        }

        protected int PagesCount { get { return _pageCounter; } }
        protected double MaxPrintAreaWidth { get; private set; }
        protected double MaxPrintAreaHeight { get; private set; }
        protected double Top
        {
            get
            {
                return _top == 0D ? _TOP_MARGIN : _top;

            }
            set { _top = value; }
        }
        protected double Left
        {
            get
            {
                return _left == 0D ? _LEFT_MARGIN : _left;

            }
            set { _left = value; }
        }
        protected int RowCounter { get; set; }

        protected void CreateFixedDoc(bool borderLess = false)
        {
            InitPrinter(borderLess);

            _fixedDoc = new FixedDocument();
                
            try
            {
                _fixedDoc.DocumentPaginator.PageSize = new Size(borderLess ? _printDialog.PrintableAreaWidth : 21.0D, borderLess ? _printDialog.PrintableAreaHeight : 29.7D);
                
                _fixedDoc.PrintTicket = _printDialog.PrintTicket;

                for (int i = 1; i <= _pageCounter; i++)
                {
                    FixedPage page = new FixedPage();

                    PageContent content = new PageContent();
                    ((IAddChild)content).AddChild(page);
                    page.Children.Add(_contentDictionary[i]);

                    _fixedDoc.Pages.Add(content);

                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }

        }

        protected Canvas CurrentCanvas
        {
            get
            {
                return _contentDictionary[PagesCount];
            }
        }

        protected Color ForeGround { get; set; }

        protected double GetTexSize(TextSize size)
        {
            if (size == TextSize.Big) return 36D;
            if (size == TextSize.Midel) return 20D;
            if (size == TextSize.Small) return 15D;
            return 12D;
        }

        protected void PrintOut(bool borderLess, bool showPrintDlg = false)
        {

            if(showPrintDlg)
            {
                bool? result = _printDialog.ShowDialog();
                if(result==true)
                {
                    Print();
                }
            }
            else
            {
                Print();
            }

        }

        protected void RestorDocument()
        {
            _fixedDoc = new FixedDocument();
            _pageCounter = 0;
            _contentDictionary.Clear();
        }

        #endregion

        #region AddPageChildren

        protected void AddTextBlock(string text, double textBlockWidth, string FontName, Color foreGround, TextSize textSize,
            FontWeight fontWeight, System.Windows.FontStyle fontStyle, double left, double top, TextAlignment alignment)
        {
            FontFamily font = new FontFamily(FontName);
            TextBlock txt = new TextBlock();

            txt.Foreground = new SolidColorBrush(foreGround);
            txt.FontSize = GetTexSize(textSize);
            txt.Width = textBlockWidth;
            txt.TextAlignment = alignment;
            txt.FontFamily = font;
            txt.FontWeight = fontWeight;
            txt.FontStyle = fontStyle;
            txt.Text = text;
            Canvas.SetLeft(txt, left);
            Canvas.SetTop(txt, top);

            CurrentCanvas.Children.Add(txt);

        }

        protected void AddRectangle(double top, double left, double width, double height, Color color, bool fill = true)
        {
            var rect = new Rectangle();
            rect.Width = width;
            rect.Height = height;

            rect.Fill = new SolidColorBrush(color);

            Canvas.SetLeft(rect, left);
            Canvas.SetTop(rect, top);

            CurrentCanvas.Children.Add(rect);
        }

        protected void AddImage(double top, double left, double width, double height, Uri imageUri)
        {
            Image img = new Image();
            BitmapImage bmp = new BitmapImage();

            using (var fs = new FileStream(imageUri.AbsolutePath, FileMode.Open, FileAccess.Read))
            {


                bmp.BeginInit();
                bmp.StreamSource = fs;
                bmp.CacheOption = BitmapCacheOption.OnLoad;
                bmp.EndInit();

                img.Source = bmp;
            }


            img.Width = width;
            img.Height = height;

            Canvas.SetTop(img, top);
            Canvas.SetLeft(img, left);

            CurrentCanvas.Children.Add(img);

        }

        protected void AddImage(double top,double left, double width, double height, MemoryStream imgStream, Stretch strechMode)
        {
            var img = new Image();
            img.Stretch = strechMode;

            img.Width = width;
            img.Height = height;
            img.Source = BitmapFrame.Create(imgStream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);

            Canvas.SetTop(img, top);
            Canvas.SetLeft(img, left);

            CurrentCanvas.Children.Add(img);

        }

        protected void AddPagIndex(string fontName, TextSize textSize, TextAlignment alignment, bool pageOf)
        {
            int maxPages = _pageCounter;
            int i = 1;
            foreach (var canvas in _contentDictionary)
            {
                _pageCounter = i;
                Top = _TOP_MARGIN + (MaxPrintAreaHeight - GetTexSize(textSize));
                Left = 0;

                var msg = !pageOf ? string.Format("Seite {0}", i) : string.Format("Seite {0} von {1}", i, maxPages);

                AddTextBlock(msg, MaxPrintAreaWidth, fontName, Colors.Black, textSize, FontWeights.Normal, FontStyles.Normal, Left, Top, alignment);

                i++;
            }
        }

        protected void ShowWindow(Window owner, string title,  ImageSource icon)
        {
            var dcv = new DocumentViewer();
            dcv.Document = _fixedDoc;

            var w = new Window();
            w.Content = dcv;
            w.Owner = owner;
            w.ShowInTaskbar = false;
            w.Title = title;
            w.Icon = icon;
            w.WindowState = WindowState.Maximized;

            w.Show();

        }

        #endregion

        #region Private

        double CentimeterToPixel(double centimeter, sd.Graphics g)
        {
            double pixel = -1;
            using (g)
            {
                pixel = centimeter * g.DpiY / 2.54d;
            }
            return pixel;
        }

        private void InitPrinter(bool borderLess)
        {

            _printDialog = new PrintDialog();
            _printDialog.PrintQueue = LocalPrintServer.GetDefaultPrintQueue();
            _printDialog.PrintTicket = _printDialog.PrintQueue.DefaultPrintTicket;
            _printDialog.PrintTicket.PageMediaSize = new PageMediaSize(PageSize);
            _printDialog.PrintTicket.PageOrientation = PageOrientation;
            
            if (!borderLess)
            {
                MaxPrintAreaWidth = _printDialog.PrintableAreaWidth - (2 * _LEFT_MARGIN);
                MaxPrintAreaHeight = _printDialog.PrintableAreaHeight - (2 * _TOP_MARGIN);
            }
        }

        private void Print()
        {
            _printDialog.PrintDocument(_fixedDoc.DocumentPaginator, null);
        }

        #endregion

    }
}



Von dieser wird die Klasse XspDocumentBase abgeleitet.



using System;
using System.IO;
using System.Printing;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Threading;
using System.Windows.Xps.Packaging;
using System.Xml;
using shp = System.Windows.Shapes;

namespace js.WPFbase.Printing
{
    public abstract class XpsDocumentBase : PrintBase
    {

        #region Readonly

        protected readonly Color _DEFAULT_FOREGROUND = Colors.Black;
        protected readonly string _docPath;

        #endregion

        #region ProtectdFolder

        protected enum FontSizees { Default, Small, Midel, Big, ExtraBig }

        protected XmlWriter _xmlWriter;
        protected int PageCounter;
        protected MultiSize _Default_Margin = new MultiSize(2.5, 2.5, 2.5, 2.5);
        protected MultiSize _Default_Pading = new MultiSize(2.5, 2.5, 2.5, 2.5);
        protected MultiSize _Default_CornrRadius = new MultiSize(5, 5, 5, 5);
        protected Task _writeTask;

        #endregion

        #region PrivateFolder

        private XpsDocument _doc;
        private IXpsFixedDocumentSequenceWriter _sequeceWriter;
        private IXpsFixedDocumentWriter _docWriter;
        private IXpsFixedPageWriter _pageWriter;
        private DispatcherTimer _deleteTimer;
        private DateTime _timerStartTime;

        #endregion

        public XpsDocumentBase()
        {
            _docPath = $"{Path.GetTempPath()}{Guid.NewGuid().ToString()}.xps";

            _deleteTimer = new DispatcherTimer();
            _deleteTimer.Interval = new TimeSpan(0, 0, 0, 0, 5);
            _deleteTimer.Tick += DeleteTimerTick;

            ForeGround = _DEFAULT_FOREGROUND;
            FontStyle = FontStyles.Normal;
            FontWeight = FontWeights.Normal;
            MarginThickness = new Thickness(2.5);
            BorderColor = Colors.Black;
            BorderBackground = new SolidColorBrush(Colors.Silver);
        }

        #region Public

        public IDocumentPaginatorSource Document { get; protected set; }

        #endregion

        #region Protected

        protected bool PrintDirect { get; set; } = false;

        protected void OpenDoc()
        {

            _doc = new XpsDocument(_docPath, FileAccess.ReadWrite);

            _sequeceWriter = _doc.AddFixedDocumentSequence();

            _docWriter = _sequeceWriter.AddFixedDocument();

            AddPage();
        }

        protected void AddPage()
        {
            _pageWriter = _docWriter.AddFixedPage();

            _xmlWriter = _pageWriter.XmlWriter;

            XmlWriter xmlWriter = _pageWriter.XmlWriter;

            xmlWriter.WriteStartElement("FixedPage");

            xmlWriter.WriteAttributeString("xmlns", "http://schemas.microsoft.com/xps/2005/06");

            xmlWriter.WriteStartElement("StackPanel");

            xmlWriter.WriteAttributeString("Margin", $"{_LEFT_MARGIN},{_TOP_MARGIN},{ _LEFT_MARGIN / 2},{_TOP_MARGIN}");
            xmlWriter.WriteAttributeString("StackPanel.Width", $"{MaxPrintAreaWidth + _LEFT_MARGIN }");

            PageCounter++;
        }

        protected void ClosePage()
        {
            _xmlWriter.WriteEndElement();
            _pageWriter.Commit();
        }

        protected void ClosDocument()
        {
            // Alle Writer beenden
            _docWriter.Commit();
            _sequeceWriter.Commit();

            Document = _doc.GetFixedDocumentSequence();

            _doc.Close();

            if (PrintDirect)
            {
                PrintQueue pq = LocalPrintServer.GetDefaultPrintQueue();
                PrintTicket pt = pq.DefaultPrintTicket;
                PrintSystemJobInfo info = pq.AddJob("Documnet", _docPath, false, pt);
            };


            _timerStartTime = DateTime.Now;
            _deleteTimer.Start();

        }

        protected System.Windows.FontStyle FontStyle { get; set; }
        protected FontWeight FontWeight { get; set; }
        protected Thickness MarginThickness { get; set; }
        protected Color BorderColor { get; set; }
        protected Brush BorderBackground;

        protected double GetFontSize(FontSizees fontSize)
        {
            if (fontSize == FontSizees.Small) return 10D;
            if (fontSize == FontSizees.Midel) return 14D;
            if (fontSize == FontSizees.Big) return 18D;
            if (fontSize == FontSizees.ExtraBig) return 24D;

            return 12D;
        }

        #endregion

        #region ControlGet

        protected TextBlock GetTextBlock(string text, FontSizees fontSize, double? width = null, TextAlignment alignement = TextAlignment.Left, FontWeight? fontWeight = null)
        {

            var txt = new TextBlock();
            txt.Text = text;
            txt.FontSize = GetFontSize(fontSize);
            txt.FontStyle = FontStyle;
            txt.FontWeight = FontWeight;
            txt.Margin = MarginThickness;
            txt.Foreground = new SolidColorBrush(ForeGround);
            txt.TextAlignment = alignement;
            txt.FontWeight = fontWeight==null ? FontWeights.Normal:fontWeight.Value;
            txt.Width = width == null ? Double.NaN : width.Value;
            return txt;
        }

        protected Border GetBorder(double borderThickness = 1D, bool margin = false, MultiSize? marginSize = null, bool padding = false, MultiSize? paddingSize = null, MultiSize? cornerRadius = null)
        {
            var b = new Border();
            b.BorderBrush = new SolidColorBrush(BorderColor);
            b.BorderThickness = new Thickness(borderThickness);
            b.CornerRadius = cornerRadius == null ? new CornerRadius(_Default_CornrRadius.Size1, _Default_CornrRadius.Size2, _Default_CornrRadius.Size3, _Default_CornrRadius.Size4) : new CornerRadius(cornerRadius.Value.Size1, cornerRadius.Value.Size2, cornerRadius.Value.Size3, cornerRadius.Value.Size4);
            b.Background = BorderBackground;

            if (margin) b.Margin = marginSize == null ? new Thickness(_Default_Margin.Size1, _Default_Margin.Size2, _Default_Margin.Size3, _Default_Margin.Size4) : new Thickness(paddingSize.Value.Size1, paddingSize.Value.Size2, paddingSize.Value.Size3, paddingSize.Value.Size1);
            if (padding) b.Padding = paddingSize == null ? new Thickness(_Default_Pading.Size1, _Default_Pading.Size2, _Default_Pading.Size3, _Default_Pading.Size4) : new Thickness(paddingSize.Value.Size1, paddingSize.Value.Size2, paddingSize.Value.Size3, paddingSize.Value.Size4);

            return b;
        }

        protected shp.Rectangle GetFilledRectangle(double height, double width, Color fillColor)
        {
            var rect = new shp.Rectangle();
            rect.Height = height;
            rect.Width = width;
            rect.Fill = new SolidColorBrush(fillColor);
            return rect;
        }

        protected shp.Rectangle GetStorkedRectangle(double height, double width, Color fillColor, Color storkColor, double storkThickness = 1D)
        {
            var rect = new shp.Rectangle();
            rect.Height = height;
            rect.Width = width;
            rect.Fill = new SolidColorBrush(fillColor);
            rect.Stroke = new SolidColorBrush(storkColor);
            rect.StrokeThickness = storkThickness;
            return rect;
        }

        #endregion

        #region ControlAdd

        protected void AddTextBlock(string text, FontSizees fontSize)
        {
            XamlWriter.Save(GetTextBlock(text, fontSize ), _xmlWriter);
        }

        protected void AddTextBlock(string text, FontSizees fontSize, double width=Double.NaN)
        {
            XamlWriter.Save(GetTextBlock(text, fontSize, width), _xmlWriter);
        }

        protected void AddTextBlock(string text, FontSizees fontSize, double width = Double.NaN, TextAlignment aligement= TextAlignment.Left)
        {
            XamlWriter.Save(GetTextBlock(text, fontSize, width, aligement), _xmlWriter);
        }

        protected void AddTextBlock(string text, FontSizees fontSize, double width = Double.NaN, TextAlignment aligement = TextAlignment.Left, FontWeight? fontWeight = null)
        {
            XamlWriter.Save(GetTextBlock(text, fontSize, width, aligement, fontWeight), _xmlWriter);
        }

        protected void AddFilledRectangle(double height, double width, Color fillColor)
        {
            XamlWriter.Save(GetFilledRectangle(height, width, fillColor), _xmlWriter);
        }

        protected void AddStorkedRectangle(double height, double width, Color fillColor, Color storkColor, double storkThickness = 1D)
        {
            XamlWriter.Save(GetStorkedRectangle(height, width, fillColor, storkColor, storkThickness), _xmlWriter);
        }

        protected void AddGrid(Grid grid)
        {
            XamlWriter.Save(grid, _xmlWriter);
        }

        protected void AddBorder(Border border)
        {
            XamlWriter.Save(border, _xmlWriter);
        }

        #endregion

     )

        #region Structs

        public struct MultiSize
        {
            internal MultiSize(double size1, double size2, double size3, double size4)
            {
                Size1 = size1;
                Size2 = size2;
                Size3 = size3;
                Size4 = size4;
            }

            internal double Size1 { get; private set; }
            internal double Size2 { get; private set; }
            internal double Size3 { get; private set; }
            internal double Size4 { get; private set; }
        }

        #endregion

    }
}


Implemtierug:



    public class MyReports
    {

        #region Const

        private const double _COLUMN_SMALL = 80D;
        private const double _COLUMNL_LARGE = 200D;

        // Maximale Anzahl der Zeilen pro Seite, muss wohl angepast werden
        private const int _MAX_ROW = 39;

        #endregion

        #region ReadonlyFolder

        private readonly double _maxPageWidth;
        private readonly List<TextBlock> _textBlockList;
        private readonly double _textBoxHeight;
        private readonly double _column_Large;
        private readonly double _columnLargeLeft;

        #endregion


        public MyReports()
        {
            _maxPageWidth = MaxPrintAreaWidth + _LEFT_MARGIN;
            _AccontNameWidth = _maxPageWidth - (4 * _COLUMN_SMALL) - 10D;
            _textBlockList = new List<TextBlock>();
            _textBoxHeight = TextHeight(_FONT_NAME, GetFontSize(FontSizees.Default)) + 5D;
            _data = new List<TransactionItem>();

            ForeGround = Colors.Black;
            FontWeight = FontWeights.Bold;
            OpenDoc();

            if (PageCounter == 0) AddPage();

            AddPageHeader(MainVewModlView.CurrentFiscalYear);
            AddReportHeader();
            AddData(MainVewModlView.CurrentFiscalYear);

            FontWeight = FontWeights.Normal;

            // Page und Document schliessen
            PageCounter = 0;
            ClosePage();
            ClosDocument();

        }

        public IDocumentPaginatorSource AccountDocument(DocumentDVMMV dv, ObservableCollection<AccountItem> data)
        {
            OpenDoc();

            if (PageCounter == 0) AddPage();

            AddPageHeader();
            AddReportHeader();

            foreach (var item in data)
            {

                _textBlockList.Clear();
          
                 // Hier je nach Spaltenanzahl Kode anpassen
                _textBlockList.Add(GetTextBlock(item.AccountNr.ToString(), FontSizees.Default, _COLUMN_SMALL - 5D));
                _textBlockList.Add(GetTextBlock(item.AccountType.ToString(), FontSizees.Default, _COLUMNL_LARGE - 5D));
                _textBlockList.Add(GetTextBlock(item.AccountName, FontSizees.Default, _columnLargeLeft - 5D));

                SetGridColumn();

                if (RowCounter > _MAX_ROW)
                {
                    RowCounter = 0;
                    AddPage();
                    AddPageHeader();
                    AddReportHeader();
                    AddReportFooter();
                }

                RowCounter++;
            }

            ClosDocument();
            PageCounter = 0;

            return Document;
        }   
 
        #region PrivateGrid

        private void SetGridColumn()
        {
            // Grid erzeugen und in Document einfügen
            var grid = GetGrid();

            for (int i = 0; i < _textBlockList.Count; i++)
            {
                Grid.SetColumn(_textBlockList[i], i);
                grid.Children.Add(_textBlockList[i]);

            }

            AddGrid(grid);
        }

        private Grid GetGrid()
        {

            // Grid erstellen und Salten sowie Spaltenbreite einstellen
            var g = new Grid();

            // KontoNr
            ColumnDefinition col1 = new ColumnDefinition();
            col1.Width = new GridLength(_COLUMN_SMALL);
            g.ColumnDefinitions.Add(col1);

            // Kontobeschreibung
            ColumnDefinition col2 = new ColumnDefinition();
            col2.Width = new GridLength(_AccontNameWidth);
            g.ColumnDefinitions.Add(col2);

            // Kontosaldo
            ColumnDefinition col3 = new ColumnDefinition();
            col3.Width = new GridLength(_COLUMN_SMALL);
            g.ColumnDefinitions.Add(col3);

            // Budget
            ColumnDefinition col4 = new ColumnDefinition();
            col4.Width = new GridLength(_COLUMN_SMALL);
            g.ColumnDefinitions.Add(col4);

            ColumnDefinition col5 = new ColumnDefinition();
            col4.Width = new GridLength(_COLUMN_SMALL);
            g.ColumnDefinitions.Add(col5);

            g.Width = _maxPageWidth;

            // Der 2. Datensatz wird grau unterlegt
            if (RowCounter % 2 == 1) g.Background = new SolidColorBrush(Colors.Silver);

            return g;
        }

        #endregion

        #region Private

        private void AddPageHeader(int year)
        {
            var tb = GetTextBlock($"Butgetauszug {year} vom {DateTime.Now.ToLongDateString()}", FontSizees.Big);
            tb.Width = _maxPageWidth;
            tb.Height = TextHeight(_FONT_NAME, GetFontSize(FontSizees.Big));
            XamlWriter.Save(tb, _xmlWriter);

            var grid = GetGrid();
            grid.Height = 40D;
            AddGrid(grid);
        }

        private void AddReportHeader()
        {
            _textBlockList.Clear();
            _textBlockList.Add(GetTextBlock("KontoNr", FontSizees.Midel, _COLUMN_SMALL - 5D));
            _textBlockList.Add(GetTextBlock("Konto", FontSizees.Midel, _AccontNameWidth - 5D));
            _textBlockList.Add(GetTextBlock(string.Empty, FontSizees.Midel, _COLUMN_SMALL - 5D, TextAlignment.Right));
            _textBlockList.Add(GetTextBlock("Budget", FontSizees.Midel, _COLUMN_SMALL - 5D, TextAlignment.Right));
            _textBlockList.Add(GetTextBlock("Budgetsaldo", FontSizees.Midel, _COLUMN_SMALL - 5D, TextAlignment.Right));


            SetGridColumn();
        }

        private void AddData()
        {

            foreach(AccountItem item in MainVewModlView.FV2MainSrv.AccountSrv.Data)
            {
                bool isAccount = item.AccountType == AccountTypes.Konto;

                if (isAccount)
                {
                    var accBalance = CurrentAccountBalance(item.AccountNr);
                    var budget = AccountBudget(item.AccountNr);
                    var balance = CurrentBudgetBalance(item.AccountNr);

                    _textBlockList.Clear();

                    _textBlockList.Add(GetTextBlock(item.AccountNr.ToString(), FontSizees.Default, _COLUMN_SMALL));
                    _textBlockList.Add(GetTextBlock(item.AccountName, FontSizees.Default, _AccontNameWidth));
                    _textBlockList.Add(GetTextBlock(string.Empty, FontSizees.Default, _COLUMN_SMALL - 5, TextAlignment.Right));
                    _textBlockList.Add(GetTextBlock(budget.ToString(_FORMAT_NUMBRE), FontSizees.Default, _COLUMN_SMALL - 5, TextAlignment.Right));
                    _textBlockList.Add(GetTextBlock(balance.ToString(_FORMAT_NUMBRE), FontSizees.Default, _COLUMN_SMALL - 5, TextAlignment.Right));

                    SetGridColumn();

                    RowCounter++;
                }
            }
        }
}


Bei Fragen fragen?

Ich hoffe, dass diese 2 Basis-Klassen und die Implementierungs-Klasse dir weiterhelfen.

Gruss Alex

Super Danke!!!