Xamarin表单将特定行绑定到代码

时间:2016-04-04 07:48:52

标签: c# xaml xamarin.forms

基本上我想将特定行绑定到.cs文件中的网格是否可能?

这是原理图

<Grid x:Name="grid1">
<Grid.RowDefinition>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /><!-- want to bind this row to a grid made in c# -->
<RowDefinition Height="Auto" />
</Grid.RowDefinition>

</Grid>

1 个答案:

答案 0 :(得分:1)

//Create an object of your stackPanel programatically. Make sure your stackpanel //has a name
StackPanel MyStackPanel = new StackPanel ();
StackPanel .Name= "stackPanel1";

Grid.SetRow(MyStackPanel , 1); 
Grid.SetColumn(MyStackPanel , 0);  // for setting it to 1st column
grid1.Children.Add(MyStackPanel );