1 year ago
#386502
magic bean
How can I call function in view in xamarin
I have a function in xamarin and I want to use the value of this return function as a column in my view. So here is my function:
public int setColumn()
{
int column = 0;
int product_number = 0;
foreach (Product product in AllProducts)
{
product_number++;
if(product_number % 3 == 0)
{
column++;
product_number = 0;
}
}
return column;
}
So this function apparently set the column number for my view. So I want to show 3 columns in one row and I am counting via looping my list. So here is my view:
<Grid HorizontalOptions="FillAndExpand">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<Button
Text="{Binding Name}"
Grid.Column="setColumn"
HorizontalOptions="Center"
VerticalOptions="Center"
TextColor="Black"
BackgroundColor="#EEF2FF"
Command="{Binding AddProductCommand}"
CommandParameter="{Binding .}"
/>
</Grid>
So here I want to call my function --> Grid.Column="setColumn" and set the column number.
xamarin
xamarin.forms
xamarin.android
xamarin.ios
xamarin-studio
0 Answers
Your Answer