146 lines
4.4 KiB
C#
146 lines
4.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media;
|
|
using System.Windows.Shapes;
|
|
|
|
namespace MetroGauges.Controls
|
|
{
|
|
public class Row
|
|
{
|
|
private List<Cell> cells = new List<Cell>();
|
|
|
|
public int Height { get; set; }
|
|
|
|
public List<Cell> Cells { get { return cells; } }
|
|
|
|
public Point StartPoint { get; set; }
|
|
|
|
public OutTable Table { get; set; }
|
|
|
|
public Row(int col, Canvas canvas)
|
|
{
|
|
Height = 30;
|
|
for (int i = 0; i < col; i++)
|
|
{
|
|
bool isLastCell = false;
|
|
if (i == col - 1)
|
|
{
|
|
isLastCell = true;
|
|
}
|
|
Cell cell = new Cell() { Index = i, Height=this.Height,IsLastCell= isLastCell, Row=this };
|
|
cell.DrawPanel = canvas;
|
|
cells.Add(cell);
|
|
}
|
|
}
|
|
|
|
public void IntiCells()
|
|
{
|
|
for (int i = 0; i < cells.Count; i++)
|
|
{
|
|
cells[i].StartPoint = new Point() { X = StartPoint.X+cells[i].Width*i , Y = StartPoint.Y };
|
|
cells[i].Draw();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public class Cell
|
|
{
|
|
public int Width { get; set; }
|
|
|
|
public int Height { get; set; }
|
|
|
|
public string Text { get; set; }
|
|
|
|
public bool IsLastCell { get; set; }
|
|
|
|
public int Index { get; set; }
|
|
|
|
public Point StartPoint { get; set; }
|
|
|
|
public Canvas DrawPanel { get; set; }
|
|
|
|
public Row Row { get; set; }
|
|
|
|
public Cell()
|
|
{
|
|
Width = 60;
|
|
}
|
|
|
|
public void Draw()
|
|
{
|
|
int strokeThickness = 1;
|
|
Line line =new Line() { Stroke= Brushes.White, StrokeThickness= strokeThickness };
|
|
//上
|
|
line.X1 = this.StartPoint.X;
|
|
line.Y1 = this.StartPoint.Y;
|
|
line.X2 = this.StartPoint.X + this.Width;
|
|
line.Y2 = this.StartPoint.Y;
|
|
DrawPanel.Children.Add(line);
|
|
//左
|
|
Line line1 = new Line() { Stroke = Brushes.White, StrokeThickness = strokeThickness };
|
|
line1.X1 = this.StartPoint.X;
|
|
line1.Y1 = this.StartPoint.Y;
|
|
line1.X2 = this.StartPoint.X;
|
|
line1.Y2 = this.StartPoint.Y+this.Height;
|
|
DrawPanel.Children.Add(line1);
|
|
//下
|
|
Line line2 = new Line() { Stroke = Brushes.White, StrokeThickness = strokeThickness };
|
|
line2.X1 = this.StartPoint.X;
|
|
line2.Y1 = this.StartPoint.Y + this.Height;
|
|
line2.X2 = this.StartPoint.X + this.Width;
|
|
line2.Y2 = this.StartPoint.Y + this.Height;
|
|
DrawPanel.Children.Add(line2);
|
|
|
|
if (this.Row.Table.DrawShaps != null)
|
|
{
|
|
this.Row.Table.DrawShaps.Add(line);
|
|
this.Row.Table.DrawShaps.Add(line1);
|
|
this.Row.Table.DrawShaps.Add(line2);
|
|
}
|
|
|
|
//最后一列 右
|
|
if (IsLastCell)
|
|
{
|
|
Line line3 = new Line() { Stroke = Brushes.White, StrokeThickness = strokeThickness };
|
|
line3.X1 = this.StartPoint.X + this.Width;
|
|
line3.Y1 = this.StartPoint.Y ;
|
|
line3.X2 = this.StartPoint.X + this.Width;
|
|
line3.Y2 = this.StartPoint.Y + this.Height;
|
|
DrawPanel.Children.Add(line3);
|
|
if (this.Row.Table.DrawShaps != null)
|
|
{
|
|
this.Row.Table.DrawShaps.Add(line3);
|
|
}
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(this.Text))
|
|
{
|
|
TextBlock textBlock = new TextBlock();
|
|
textBlock.Text = this.Text;
|
|
textBlock.Foreground = new SolidColorBrush(Colors.White);
|
|
|
|
Point point = new Point() { X = this.StartPoint.X + 10, Y = this.StartPoint.Y + (this.Height / 2 + 8) };
|
|
textBlock.DataContext = point;
|
|
|
|
Canvas.SetLeft(textBlock, this.StartPoint.X + 10);
|
|
Canvas.SetTop(textBlock, this.StartPoint.Y + this.Height / 2 - 8);
|
|
|
|
DrawPanel.Children.Add(textBlock);
|
|
if (this.Row.Table.DrawShaps != null)
|
|
{
|
|
this.Row.Table.DrawShaps.Add(textBlock);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|