@MisterADK

Как код будет выглядеть на c#?

Здравствуйте всем! Как следующий код xaml написать на c#:
<ScrollView>
    <StackLayout Orientation="Vertical">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
                
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
               
             
            <Label
            Grid.Column="1"
            FontSize="Medium"
            HorizontalTextAlignment="Center"
            Text="I"
            VerticalTextAlignment="Center" />
            <Label
            Grid.Column="2"
            FontSize="Medium"
            HorizontalTextAlignment="Center"
            Text="II"
            VerticalTextAlignment="Center" />
            <Label
            Grid.Column="3"
            FontSize="Medium"
            HorizontalTextAlignment="Center"
            Text="III"
            VerticalTextAlignment="Center" />
            <Label
            Grid.Row="1"
            FontSize="Medium"
            HorizontalTextAlignment="Center"
            Text="14" />
            <Label
            Grid.Row="2"
            FontSize="Medium"
            HorizontalTextAlignment="Center"
            Text="16" />
            <Label
            Grid.Row="3"
            FontSize="Medium"
            HorizontalTextAlignment="Center"
            Text="18" />
            <Label
            Grid.Row="4"
            FontSize="Medium"
            HorizontalTextAlignment="Center"
            Text="20" />
            <Label
            Grid.Row="5"
            FontSize="Medium"
            HorizontalTextAlignment="Center"
            Text="22" />
            <Label
            Grid.Row="6"
            FontSize="Medium"
            HorizontalTextAlignment="Center"
            Text="24" />
            <Label
            Grid.Row="7"
            FontSize="Medium"
            HorizontalTextAlignment="Center"
            Text="26" />
            <Label
            Grid.Row="8"
            FontSize="Medium"
            HorizontalTextAlignment="Center"
            Text="28" />
            <Label
            Grid.Row="9"
            FontSize="Medium"
            HorizontalTextAlignment="Center"
            Text="30" />
            <Label
            Grid.Row="10"
            FontSize="Medium"
            HorizontalTextAlignment="Center"
            Text="32" />
            <Label
            Grid.Row="11"
            FontSize="Medium"
            HorizontalTextAlignment="Center"
            Text="34" />
            <Label
            Grid.Row="12"
            FontSize="Medium"
            HorizontalTextAlignment="Center"
            Text="36" />
            <Label
            Grid.Row="13"
            FontSize="Medium"
            HorizontalTextAlignment="Center"
            Text="38" />
            <Label
            Grid.Row="14"
            FontSize="Medium"
            HorizontalTextAlignment="Center"
            Text="40" />
            <Label
            Grid.Row="15"
            FontSize="Medium"
            HorizontalTextAlignment="Center"
            Text="42" />
            <Label
            Grid.Row="16"
            FontSize="Medium"
            HorizontalTextAlignment="Center"
            Text="44" />
            <Button
            Grid.Row="1"
            Grid.Column="1"
            BindingContext="{Binding Items[0]}"
            Command="{Binding BindingContext.ClickCommand, Source={RelativeSource Mode=FindAncestor, AncestorType={x:Type d:ContentPage}}}"
            CommandParameter="{Binding .}"
            Style="{StaticResource selectableBtn}"
            Text="{Binding Value}" />
            <Button
            Grid.Row="1"
            Grid.Column="2"
            BindingContext="{Binding Items[1]}"
            Command="{Binding BindingContext.ClickCommand, Source={RelativeSource Mode=FindAncestor, AncestorType={x:Type d:ContentPage}}}"
            CommandParameter="{Binding .}"
            Style="{StaticResource selectableBtn}"
            Text="{Binding Value}" />
            <Button
            Grid.Row="1"
            Grid.Column="3"
            BindingContext="{Binding Items[2]}"
            Command="{Binding BindingContext.ClickCommand, Source={RelativeSource Mode=FindAncestor, AncestorType={x:Type d:ContentPage}}}"
            CommandParameter="{Binding .}"
            Style="{StaticResource selectableBtn}"
            Text="{Binding Value}" />
            <Button
            Grid.Row="2"
            Grid.Column="1"
            BindingContext="{Binding Items[3]}"
            Command="{Binding BindingContext.ClickCommand, Source={RelativeSource Mode=FindAncestor, AncestorType={x:Type d:ContentPage}}}"
            CommandParameter="{Binding .}"
            Style="{StaticResource selectableBtn}"
            Text="{Binding Value}" />
            <Button
            Grid.Row="2"
            Grid.Column="2"
            BindingContext="{Binding Items[4]}"
            Command="{Binding BindingContext.ClickCommand, Source={RelativeSource Mode=FindAncestor, AncestorType={x:Type d:ContentPage}}}"
            CommandParameter="{Binding .}"
            Style="{StaticResource selectableBtn}"
            Text="{Binding Value}" />
            <Button
            Grid.Row="2"
            Grid.Column="3"
            BindingContext="{Binding Items[5]}"
            Command="{Binding BindingContext.ClickCommand, Source={RelativeSource Mode=FindAncestor, AncestorType={x:Type d:ContentPage}}}"
            CommandParameter="{Binding .}"
            Style="{StaticResource selectableBtn}"
            Text="{Binding Value}" />
            <Button
            Grid.Row="3"
            Grid.Column="1"
            BindingContext="{Binding Items[6]}"
            Command="{Binding BindingContext.ClickCommand, Source={RelativeSource Mode=FindAncestor, AncestorType={x:Type d:ContentPage}}}"
            CommandParameter="{Binding .}"
            Style="{StaticResource selectableBtn}"
            Text="{Binding Value}" />
            <Button
            Grid.Row="3"
            Grid.Column="2"
            BindingContext="{Binding Items[7]}"
            Command="{Binding BindingContext.ClickCommand, Source={RelativeSource Mode=FindAncestor, AncestorType={x:Type d:ContentPage}}}"
            CommandParameter="{Binding .}"
            Style="{StaticResource selectableBtn}"
            Text="{Binding Value}" />
            <Button
            Grid.Row="3"
            Grid.Column="3"
            BindingContext="{Binding Items[8]}"
            Command="{Binding BindingContext.ClickCommand, Source={RelativeSource Mode=FindAncestor, AncestorType={x:Type d:ContentPage}}}"
            CommandParameter="{Binding .}"
            Style="{StaticResource selectableBtn}"
            Text="{Binding Value}" />
            <Button
            Grid.Row="4"
            Grid.Column="1"
            BindingContext="{Binding Items[9]}"
            Command="{Binding BindingContext.ClickCommand, Source={RelativeSource Mode=FindAncestor, AncestorType={x:Type d:ContentPage}}}"
            CommandParameter="{Binding .}"
            Style="{StaticResource selectableBtn}"
            Text="{Binding Value}" />
            <Button
            Grid.Row="4"
            Grid.Column="2"
            BindingContext="{Binding Items[10]}"
            Command="{Binding BindingContext.ClickCommand, Source={RelativeSource Mode=FindAncestor, AncestorType={x:Type d:ContentPage}}}"
            CommandParameter="{Binding .}"
            Style="{StaticResource selectableBtn}"
            Text="{Binding Value}" />
            <Button
            Grid.Row="4"
            Grid.Column="3"
            BindingContext="{Binding Items[11]}"
            Command="{Binding BindingContext.ClickCommand, Source={RelativeSource Mode=FindAncestor, AncestorType={x:Type d:ContentPage}}}"
            CommandParameter="{Binding .}"
            Style="{StaticResource selectableBtn}"
            Text="{Binding Value}" />
        </Grid>
    </StackLayout>
    </ScrollView>

(Кнопки еще присутствуют не все)
Задача состоим в том, чтобы создать массив кнопок, а затем циклически придавать значение Grid.Row и Grid.Column. Желательно чтобы массив кнопок был двумерный Button[,] b = new Button[3, 16];
Подскажите, пожалуйста, как это делается, заранее спасибо!
  • Вопрос задан
  • 275 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы