Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net silverlight:如何以编程方式设置附加属性_.net_Silverlight_Silverlight 2.0 - Fatal编程技术网

.net silverlight:如何以编程方式设置附加属性

.net silverlight:如何以编程方式设置附加属性,.net,silverlight,silverlight-2.0,.net,Silverlight,Silverlight 2.0,假设我有一个带有一些行定义的网格,以及该网格中的一个子控件。如何以编程方式设置子控件的Grid.Row属性?我不能100%确定这在SilverLight中是否存在,但在WPF中,可以对定义附加属性的类型调用静态方法(称为SetX,其中X是属性),并将其传递给要设置值的控件,以及值: Grid.SetRow(MyControl, myRowNumber); textBlock.SetValue(Grid.RowProperty, 3); textBlock.SetValue(Grid.Row

假设我有一个带有一些行定义的网格,以及该网格中的一个子控件。如何以编程方式设置子控件的Grid.Row属性?

我不能100%确定这在SilverLight中是否存在,但在WPF中,可以对定义附加属性的类型调用静态方法(称为SetX,其中X是属性),并将其传递给要设置值的控件,以及值:

Grid.SetRow(MyControl, myRowNumber); 
textBlock.SetValue(Grid.RowProperty, 3);
textBlock.SetValue(Grid.RowProperty, null);
要设置该值,请执行以下操作:

Grid.SetRow(MyControl, myRowNumber); 
textBlock.SetValue(Grid.RowProperty, 3);
textBlock.SetValue(Grid.RowProperty, null);
要重置该值,请执行以下操作:

Grid.SetRow(MyControl, myRowNumber); 
textBlock.SetValue(Grid.RowProperty, 3);
textBlock.SetValue(Grid.RowProperty, null);

实际上,要清除某个值,应使用以下命令:

textBlock.ClearValue(Grid.RowProperty);

我不太清楚,你可以把它设为空。如果你愿意,你可以使用习惯用法:Grid.SetRow(textBlock,3);附加属性通常有Get和Set方法(虽然我不认为这是强制性的,所以可能会有例外)。我注意到(这是SL3 beta版)要更改子控件的位置,您不能只设置此属性--您需要从父网格中删除该控件,按此处所示设置属性,然后将其重新添加到父级。