如何设置特定行的同一网格的不透明度

如何设置特定行的同一网格的不透明度

本文介绍了C#中:如何设置特定行的同一网格的不透明度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的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);
 

下面是该例子。在这里我为每个两行两个新网格和相关文本框加入到每个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.

这篇关于C#中:如何设置特定行的同一网格的不透明度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 16:38