3

I'm having some troubles adding a ContentView inside a ContentPage in Xamarin.Form,

I've followed the tutorial at: Xamarin Forms - How to display content from one xaml inside another

but with no luck.

Here is the code of the contentView that i want to add:

<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
             x:Class="HangoverBusiness.Proprietario.celle.view_evento">
        <ContentView.Content>
        <Grid HeightRequest="220" RowSpacing="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="20" />
                <RowDefinition Height="5" />
            </Grid.RowDefinitions>
            <Image Grid.Row="0" Grid.RowSpan="2" Grid.ColumnSpan="2" Aspect="AspectFill">
                <Image.Source>
                    <UriImageSource Uri="{Binding ImmagineCopertina}" CachingEnabled="True">
                        <UriImageSource.CacheValidity>
                            <x:TimeSpan>0,0,15,0</x:TimeSpan>
                        </UriImageSource.CacheValidity>
                    </UriImageSource>
                </Image.Source>
            </Image>
            <Image Grid.Row="0" Grid.Column="0" Source="{Binding iconaTop}" HeightRequest="50" WidthRequest="50" VerticalOptions="Start" HorizontalOptions="Start" Margin="5,5,0,0" />
            <Frame Grid.Row="1" Grid.Column="0" OutlineColor="WhiteSmoke" BackgroundColor="Transparent" CornerRadius="10" Margin="5,0,0,0" Padding="0,0,0,0" HorizontalOptions="Start" VerticalOptions="End" HasShadow="False">
                <StackLayout VerticalOptions="CenterAndExpand" HorizontalOptions="Center" Margin="0,3,0,3" Spacing="0" Padding="0" BackgroundColor="Transparent" WidthRequest="60">
                    <Label Text="{Binding DataInizioEvento, StringFormat='{0: d}'}" FontSize="Medium" TextColor="White" HorizontalOptions="Center" Margin="0" />
                    <Label Text="{Binding DataInizioEvento, StringFormat='{0: MMM}'}" FontSize="Medium" TextColor="White" HorizontalTextAlignment="Center" Margin="0" />
                    <Label Text="{Binding DataInizioEvento, StringFormat='{0: HH:mm}'}" FontSize="Small" TextColor="LightGray" HorizontalOptions="Center" Margin="0" />
                </StackLayout>
            </Frame>
            <StackLayout Spacing="0" Grid.Row="1" Grid.Column="1" Margin="0,0,5,5" Orientation="Vertical" VerticalOptions="EndAndExpand" HorizontalOptions="End">
                <Label Text="{Binding NomeEvento}" Margin="0,0,0,5" TextColor="White" FontSize="Large" FontAttributes="Bold" HorizontalOptions="End" />
                <Label Text="{Binding NomeLocale}" Margin="0,0,0,5" TextColor="White" FontSize="Small" HorizontalOptions="End" />
            </StackLayout>
            <BoxView Grid.Row="2" Grid.ColumnSpan="2" BackgroundColor="#f29836" HorizontalOptions="FillAndExpand" />
            <Label Grid.Row="2" Grid.Column="0" Text="{Binding Genere}" TextColor="WhiteSmoke" FontSize="Small" HorizontalOptions="Start" VerticalOptions="Start" HorizontalTextAlignment="Start" Margin="5,0,0,0" />
            <Label Grid.Row="2" Grid.Column="1" Text="{Binding Prezzo, StringFormat='{0:N} Euro'}" TextColor="WhiteSmoke" FontSize="Small" HorizontalOptions="End" VerticalOptions="Start" HorizontalTextAlignment="End" Margin="0,0,5,0" />
            <BoxView Grid.Row="3" Grid.ColumnSpan="2" HorizontalOptions="FillAndExpand" Color="#515E3A" HeightRequest="10" />
        </Grid>
    </ContentView.Content>
</ContentView>

this is the content page where i want to add the content view:

<?xml version="1.0" encoding="utf-8"?>
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"

    x:Class="HangoverBusiness.Proprietario.Eventi.PaginaEvento" 
                     xmlns:local="clr-namespace:HangoverBusiness.Proprietario.celle">
            <ContentPage.Content>
                <ScrollView>
                    <local:view_evento />
                    <ListView x:Name="listaParametri" 
                              Grid.Row="3" 
                              Margin="0,0,0,30" 
                              BackgroundColor="White" 
                              HasUnevenRows="True" 
                              SeparatorVisibility="Default" 
                              ItemSelected="listaParametri_ItemSelected">
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <ViewCell>
                                    <Grid Margin="8" 
                                          HorizontalOptions="FillAndExpand">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="100" />
                                        </Grid.ColumnDefinitions>
                                        <Label Text="{Binding Chiave}" 
                                               TextColor="Blue" 
                                               FontSize="20" 
                                               FontAttributes="Bold" 
                                               Grid.Column="0" 
                                               HorizontalOptions="Start" 
                                               VerticalTextAlignment="Center" />
                                        <Label Text="{Binding Parametro}" 
                                               TextColor="Blue" 
                                               FontSize="18" 
                                               Grid.Column="1" 
                                               VerticalTextAlignment="Center" 
                                               HorizontalOptions="End" />
                                    </Grid>
                                </ViewCell>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                        <ListView.Footer>
                            <StackLayout Orientation="Horizontal">
                            </StackLayout>
                        </ListView.Footer>
                    </ListView>
                </ScrollView>
            </ContentPage.Content>
        </ContentPage>

I'm trying to call the content view by using "local:view_evento" but at runtime I see nothing, any suggestions?

Thanks.

Giulio Serra
  • 253
  • 1
  • 6
  • 15
  • your first set of a XAML is a ContentPage, not a ContentView. – Jason Mar 14 '18 at 14:25
  • 1
    First of all, here's some advice: [don't use `ListView` inside a `ScrollView`](https://stackoverflow.com/questions/6210895/listview-inside-scrollview-is-not-scrolling-on-android/6211286#6211286). If you hafta use a `ScrollView`, be sure to keep only one child inside it, otherwise just the last one will be shown. You can wrap the views with a `StackLayout`, for example – Diego Rafael Souza Mar 14 '18 at 14:38
  • 1
    Define "some troubles" and "no luck". What errors did you get? What about the code that initializes the Xamarin.Form?? – Steak Overflow Mar 14 '18 at 14:43
  • The question missed a huge chunk of code, sorry guys. – Giulio Serra Mar 15 '18 at 12:24
  • A scrollview can only have a single content. That's probably hindering your view. A stacklayout (with your view and listview) as a child to the scrollview is a good option. – Sparsha Bhattarai Mar 15 '18 at 15:30

0 Answers0