C#中:如何设置特定行的同一网格的不透明度明度、网格、不透、如何设置

2023-09-06 11:04:11 作者:白衣酒客

我的Silverlight C#devloper,我这种情况解释了以下快照下:

正如你可以看到我有一个网格(在使用C#,只给我选择创建prgramtically)。

和该网格的第一行(总是可见的)我有复选框,这对检查组第二次全行的不透明度为0.3并取消选中这台3全行的不透明度为0.3(所有三列)。

我试做,这是(可能是错的):(因为它会造成整个childGrid的不透明度不只是行,但我想的不透明度横行的检查并取消选中复选框)

 电网childGrid =新的Grid();
childGrid.ColumnDefinitions.Add(新ColumnDefinition());
childGrid.ColumnDefinitions.Add(新ColumnDefinition());
childGrid.ColumnDefinitions.Add(新ColumnDefinition());
的for(int i = 0; I< totalRows;我++)
{
    childGrid.RowDefinitions.Add(新RowDefinition(){
        身高= GridLength.Auto
    });
}
复选框CHB =新的复选框();
chb.Checked + =(O,E)=>
  {
    txtblkShowStatus.Text = param.Parameter [指数] .Component.Attributes.Showstatus;
    TextBlock的TXT =新的TextBlock();
    txt.Text =你好,从第二排;
    Grid.SetColumn(TXT,1);
    Grid.SetRow(TXT,1);
    // childGrid.Opacity = 0.3;
    childGrid.Children.Add(TXT);
};
chb.Unchecked + =(O,E)=>
    {
    txtblkShowStatus.Text =否;
    TextBlock的TXT =新的TextBlock();
    txt.Text =你好,从第三行;
    Grid.SetColumn(TXT,1);
    Grid.SetRow(TXT,2);
    // childGrid.Opacity = 0.3;
    childGrid.Children.Add(TXT);
};

Grid.SetColumn(txtblkShowStatus,2);
Grid.SetRow(txtblkShowStatus,0);
childGrid.Children.Add(txtblkShowStatus);
 

如何实现它的主意?任何一件code或逻辑的帮助是AP preciated。 或你能不能解释一下,如果你有anohter逻辑做达到同样的

解决方案

 电网childGrid =新的Grid();

    电网Grdrow1 =新的Grid();
    电网Grdrow2 =新的Grid();

    childGrid.ColumnDefinitions.Add(新ColumnDefinition());
    childGrid.ColumnDefinitions.Add(新ColumnDefinition());
    childGrid.ColumnDefinitions.Add(新ColumnDefinition());
    的for(int i = 0;我3;;我++)
    {
        childGrid.RowDefinitions.Add(新RowDefinition()
        {
            身高= GridLength.Auto
        });
    }
    复选框CHB =新的复选框();
    chb.Content =复选框;
    chb.Checked + =(O,E)=>
    {
        TextBlock的TXT =新的TextBlock();
        txt.Text =你好,从第二排;
        Grid.SetColumn(Grdrow1,1);
        Grid.SetRow(Grdrow1,1);
        Grdrow1.Children.Add(TXT);


        Grdrow2.Opacity = 0;
        Grdrow1.Opacity = 1;


        childGrid.Children.Add(Grdrow1);
    };
    chb.Unchecked + =(O,E)=>
    {
        TextBlock的TXT =新的TextBlock();
        txt.Text =你好,从第三行;
        Grid.SetColumn(Grdrow2,1);
        Grid.SetRow(Grdrow2,2);
        Grdrow2.Children.Add(TXT);


        Grdrow2.Opacity = 1;
        Grdrow1.Opacity = 0;


        childGrid.Children.Add(Grdrow2);
    };

    childGrid.Children.Add(CHB);
    LayoutRoot.Children.Add(childGrid);
 
Ps野教程│我有能把人变 透明 的技能,你要不要试试

下面是该例子。 在这里我为每个两行两个新网格和相关文本框加入到每个row.then之后网格将被添加到子格。

然后用户选中的复选框,第二排电网将被隐藏,另外一个可见的,那么泛滥,却反其道而行之。您可以更改不透明度参数。

I am silverlight c# devloper and i am under a situation which explained by snapshot below:

As you can see i have a grid (have to create prgramtically using c#, only option given to me).

And the first row(always visible) of that grid i have checkbox which on checking sets opacity of second full row to 0.3 and on unchecking it sets opacity of 3rd full row to 0.3 (all the three columns).

My try to do this is (probably wrong): (because it will create the opacity of whole childGrid not just row but i want the opacity row-wise on check and un-check of checkBox)

Grid childGrid = new Grid();
childGrid.ColumnDefinitions.Add(new ColumnDefinition());
childGrid.ColumnDefinitions.Add(new ColumnDefinition());
childGrid.ColumnDefinitions.Add(new ColumnDefinition());
for (int i = 0; i < totalRows; i++) 
{
    childGrid.RowDefinitions.Add(new RowDefinition() {
        Height = GridLength.Auto
    });
}
CheckBox chb = new CheckBox();
chb.Checked += (o, e) => 
  {
    txtblkShowStatus.Text = param.Parameter[index].Component.Attributes.Showstatus;
    TextBlock txt = new TextBlock();
    txt.Text = "Hello from second row";
    Grid.SetColumn(txt, 1);
    Grid.SetRow(txt, 1);
    // childGrid.Opacity = 0.3;
    childGrid.Children.Add(txt);
};
chb.Unchecked += (o, e) => 
    {
    txtblkShowStatus.Text = "No";
    TextBlock txt = new TextBlock();
    txt.Text = "Hello from third row";
    Grid.SetColumn(txt, 1);
    Grid.SetRow(txt, 2);
    // childGrid.Opacity = 0.3;
    childGrid.Children.Add(txt);
};

Grid.SetColumn(txtblkShowStatus, 2);
Grid.SetRow(txtblkShowStatus, 0);
childGrid.Children.Add(txtblkShowStatus);

How to achieve it any idea ? Any piece of code or logic for help is appreciated. Or could you please explain if you have anohter logic to do achieve the same

解决方案

    Grid childGrid = new Grid();

    Grid Grdrow1 = new Grid();
    Grid Grdrow2 = new Grid();            

    childGrid.ColumnDefinitions.Add(new ColumnDefinition());
    childGrid.ColumnDefinitions.Add(new ColumnDefinition());
    childGrid.ColumnDefinitions.Add(new ColumnDefinition());
    for (int i = 0; i < 3; i++)
    {
        childGrid.RowDefinitions.Add(new RowDefinition()
        {
            Height = GridLength.Auto
        });
    }
    CheckBox chb = new CheckBox();
    chb.Content = "Checkbox";
    chb.Checked += (o, e) =>
    {
        TextBlock txt = new TextBlock();
        txt.Text = "Hello from second row";
        Grid.SetColumn(Grdrow1, 1);
        Grid.SetRow(Grdrow1, 1);
        Grdrow1.Children.Add(txt);


        Grdrow2.Opacity = 0;
        Grdrow1.Opacity = 1;


        childGrid.Children.Add(Grdrow1);
    };
    chb.Unchecked += (o, e) =>
    {
        TextBlock txt = new TextBlock();
        txt.Text = "Hello from third row";
        Grid.SetColumn(Grdrow2, 1);
        Grid.SetRow(Grdrow2, 2);
        Grdrow2.Children.Add(txt);


        Grdrow2.Opacity = 1;
        Grdrow1.Opacity = 0;


        childGrid.Children.Add(Grdrow2);
    };

    childGrid.Children.Add(chb);
    LayoutRoot.Children.Add(childGrid);

Here is the example. In here I create two new grids for each two rows, and related text boxes added to the each row.then after that grids will be added to the child grid.

Then user check the check box 2nd row grid will be hidden and other one visible, then unchecked and do the opposite. You can change the opacity parameters.