简体   繁体   中英

How to color a particular row of a grid in c# using silverlight

I am working on c# silverlight. I have to color(Green) the particular column which is created using c#.

I have grid with 6 rows and 3 columns like this:

 Grid myGrid = new Grid();
            myGrid.Width = 350;
            myGrid.Height = 280;
            myGrid.HorizontalAlignment = HorizontalAlignment.Left;
            myGrid.VerticalAlignment = VerticalAlignment.Top;
            myGrid.ShowGridLines = false;
            ColumnDefinition colDef1 = new ColumnDefinition();
            ColumnDefinition colDef2 = new ColumnDefinition();
            ColumnDefinition colDef3 = new ColumnDefinition();
            myGrid.ColumnDefinitions.Add(colDef1);
            myGrid.ColumnDefinitions.Add(colDef2);
            myGrid.ColumnDefinitions.Add(colDef3);
            RowDefinition rowDef1 = new RowDefinition();
            RowDefinition rowDef2 = new RowDefinition();
            RowDefinition rowDef3 = new RowDefinition();
            RowDefinition rowDef4 = new RowDefinition();
            RowDefinition rowDef5 = new RowDefinition();
            RowDefinition rowDef6 = new RowDefinition();

            myGrid.RowDefinitions.Add(rowDef1);
            myGrid.RowDefinitions.Add(rowDef2);
            myGrid.RowDefinitions.Add(rowDef3);
            myGrid.RowDefinitions.Add(rowDef4);
            myGrid.RowDefinitions.Add(rowDef5);
            myGrid.RowDefinitions.Add(rowDef6);

Now if i have to color second full row(i mean in 3 columns in this row as well) of this grid then how i will do this ?

var greenBackgroundBorder = new Border(){
    Background=new SolidColorBrush(Colors.Green)};
myGrid.Children.Add(greenBackgroundBorder);

// stay always behind other elements
Canvas.SetZOder(greenBackgroundBorder, -100);

//entire second row
Grid.SetColumnSpan(greenBackgroundBorder,3);
Grid.SetRow(greenBackgroundBorder, 1 );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM