以编程方式创建网格边框

时间:2012-01-02 13:08:51

标签: c# wpf grid

早上好,

我正在以编程方式在网格中创建列,我需要每个单元格的边框。 我让“showGridLines”为真,但我知道这是不对的,因为那些gridLines不适合生产。 如何以编程方式为每个单元格设置边框?

以下代码显示了我如何创建列:

        public void ColumnCreator(double divPattern, DateTime initial, DateTime final) 
        {   
        double leftMargin = 0;
        int initialPosition =  (int) SecondsFromMidnight(initial);  
        TimeSpan interval = final.Subtract(initial);
        int divisionPattern = Convert.ToInt16(divPattern);
        int increaseLabelTime = 0;
        AddLabel(initial, leftMargin);

        for (int i = initialPosition; i <=  (initialPosition+ interval.TotalSeconds); i += divisionPattern)
        {
            DateTime dt = initial;
            internalGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(divisionPattern, 
                GridUnitType.Pixel) });
            leftMargin += divisionPattern;
            increaseLabelTime += divisionPattern;
            dt = dt.Add(new TimeSpan(0, 0, increaseLabelTime));
            AddLabel(dt, leftMargin);
        }

    }

提前致谢...:)

1 个答案:

答案 0 :(得分:0)

您需要在每个单元格中添加Border,并将内容添加到Border Content。相应地设置BorderThicknessBorderColor