Exemple #1
0
 public ListStringView()
 {
     InitializeComponent();
     SourceData = new List <object>();
     IndexChoosenElementSourceData             = 0;
     IndexCurrentFirstVisibleElementSourceData = 0;
     borderColor             = Brushes.DarkGray;
     shadowColor             = Brushes.Black;
     this.vScrollBar.Minimum = 0;
     this.vScrollBar.Maximum = 0;
     //по-умолчанию
     this.blockSize = new BlockSizeTemplate(20, new List <int>()
     {
         50, 50
     });
     this.headerTemplate = new DataListTemplate(new ViewTemplate(Brushes.White, "Arial", 12, Brushes.Black), new List <string>()
     {
         "NoNe", "NoNe"
     });
 }
Exemple #2
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);
            Size DrawSize = new Size(this.RenderSize.Width - this.vScrollBar.RenderSize.Width, this.RenderSize.Height - this.hScrollBar.RenderSize.Height);
            Rect DrawRect = new Rect(new Point(0, 0), DrawSize);

            hScrollBar.Maximum = ((this.blockSize.FullWidth - DrawSize.Width) >= 0) ? this.blockSize.FullWidth - DrawSize.Width : 0;
            if (hScrollBar.Maximum == hScrollBar.Minimum)
            {
                hScrollBar.IsEnabled = false;
            }
            else
            {
                hScrollBar.IsEnabled = true;
            }
            drawingContext.DrawRectangle(Brushes.White, null, DrawRect);
            drawingContext.PushClip(new RectangleGeometry(DrawRect));
            //отрисовка заголовка
            Point curLocCell = new Point(0, 0);

            curLocCell.X = -this.hScrollBar.Value;
            drawingContext.DrawRectangle(this.HeaderTemplate.ViewT.ColorBackground, null, new Rect(curLocCell, new Size(this.BlockSize.FullWidth, this.blockSize.Height)));
            for (int i = 0; i < this.blockSize.ListColumnWidth.Count; i++)
            {
                Rect cellRect = new Rect(new Point(curLocCell.X + 1, curLocCell.Y + 1), new Size(this.blockSize.ListColumnWidth[i] - 2, this.blockSize.Height - 2));
                drawingContext.DrawRectangle(null, new Pen(BorderColor, 1), cellRect);
                DrawBoldTxt(drawingContext, this.HeaderTemplate.ListColumnText[i], cellRect, this.HeaderTemplate.ViewT.FontColor,
                            new Typeface(this.HeaderTemplate.ViewT.FontName), this.HeaderTemplate.ViewT.FontSize - 2);
                curLocCell.X += this.blockSize.ListColumnWidth[i];
            }
            //отрисовка строк
            int MaxIndex = (int)(DrawSize.Height / this.blockSize.Height) + this.IndexCurrentFirstVisibleElementSourceData;

            curLocCell.Y += this.blockSize.Height;
            curLocCell.X  = -this.hScrollBar.Value;
            for (int j = this.IndexCurrentFirstVisibleElementSourceData; j < MaxIndex; j++)
            {
                if (this.SourceDataElementConvert == null)
                {
                    return;
                }
                if ((j >= this.SourceData.Count) || (j < 0))
                {
                    break;
                }
                DataListTemplate currentItem = this.SourceDataElementConvert(SourceData[j], j);
                drawingContext.DrawRectangle(currentItem.ViewT.ColorBackground, null, new Rect(curLocCell, new Size(this.BlockSize.FullWidth, this.blockSize.Height)));
                Point shadowLocPt = curLocCell;
                //отрисовка одной строки
                for (int i = 0; i < this.blockSize.ListColumnWidth.Count; i++)
                {
                    Rect cellRect = new Rect(curLocCell, new Size(this.blockSize.ListColumnWidth[i], this.blockSize.Height));
                    drawingContext.DrawRectangle(null, new Pen(BorderColor, 1), cellRect);
                    //форматируем текст для рисования
                    FormattedText txt = new FormattedText(currentItem.ListColumnText[i],
                                                          CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface(currentItem.ViewT.FontName),
                                                          currentItem.ViewT.FontSize, currentItem.ViewT.FontColor);
                    txt.MaxTextWidth  = cellRect.Width;;
                    txt.MaxTextHeight = cellRect.Height;
                    txt.TextAlignment = TextAlignment.Justify;
                    //рисуем текст
                    drawingContext.DrawText(txt, cellRect.Location);
                    curLocCell.X += this.blockSize.ListColumnWidth[i];
                }
                //отрисовка тени
                if (j == IndexChoosenElementSourceData)
                {
                    drawingContext.PushOpacity(0.5);
                    drawingContext.DrawRectangle(this.shadowColor, null, new Rect(shadowLocPt, new Size(this.BlockSize.FullWidth, this.blockSize.Height)));
                    drawingContext.Pop();
                }
                curLocCell.X  = -this.hScrollBar.Value;
                curLocCell.Y += this.blockSize.Height;
            }
        }