M
M
MisterADK2020-08-03 10:11:08
WPF
MisterADK, 2020-08-03 10:11:08

How would the code look like in c#?

Hello everyone! How to write the following xaml code in 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>

(Buttons are not all present yet)
The task is to create an array of buttons, and then cyclically assign a value to Grid.Row and Grid.Column. It is desirable that the array of buttons be two-dimensional . Tell me, please, how this is done, thanks in advance! Button[,] b = new Button[3, 16];

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question