I'm creating a cross platform Xamarin.Forms app. In a page, I've the following list view.
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid x:Name="activityGrid">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Text="{Binding Name}" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
Here as you can see I have one row and two columns for each item in the list view. the first label I've defined will be set in Row=0
and Column=0
, as that is the default. Now with respect to Row=0
and Column =1
, I want it to be a Switch or Entry based on some criteria. Here's my code behind.
foreach (var activity in activities)
{
if (activity.Measurement == 0)
{
Switch yesNo = new Switch();
}
else
{
Entry measure = new Entry();
}
}
Now help me add the children to the Grid Layout based on the requirement.
要以编程方式向网格添加控件,请执行以下操作:
activityGrid.Children.Add(control, col, row);
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.