Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

How to add items to custom control

$
0
0

I would like to build a custom Frame control with an SKCanvasView as a background.

I already have a "SolidBox" control which works wonderfully.

Currently, I make a Grid, fill it with a SolidBox, then put my content inside.

I would like to do this the way the Frame control does.

Here is what I currently do:

<Grid HorizontalOptions="Center"
      VerticalOptions="Center">

    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>

    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
    </Grid.ColumnDefinitions>

    <controls:SolidBox Grid.Row="0" Grid.Column="0"
                       HorizontalOptions="FillAndExpand"
                       VerticalOptions="FillAndExpand"
                       LineColor="DarkBlue"
                       LineThickness="4"
                       CornerRadius="5"
                       InnerColor="White"/>

    <Grid Grid.Row="0" Grid.Column="0"
          HorizontalOptions="Center"
          VerticalOptions="Center"
          Margin="5">

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <!-- Add my content -->
        <Label Grid.Row="0" Text="Line 1"/>
        <Label Grid.Row="1" Text="Line 2"/>
        <Label Grid.Row="2" Text="Line 3"/>

    </Grid>

</Grid>

What I would like to do is create a control to simplify things

<controls:CustomFrame HorizontalOptions="FillAndExpand"
                      VerticalOptions="FillAndExpand"
                      LineColor="DarkBlue"
                      LineThickness="4"
                      CornerRadius="5"
                      InnerColor="White"/>

    <StackLayout Orientation="Vertical">

        <!-- Add my content -->
        <Label Grid.Row="0" Text="Line 1"/>
        <Label Grid.Row="1" Text="Line 2"/>
        <Label Grid.Row="2" Text="Line 3"/>

    </StackLayout>

</controls:CustomFrame>

But I don't know how to handle the children of the control in the xaml.cs ...
When the StackLayout is added in xaml, how do I handle that in my xaml.cs?


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>