我在Xamarin.Form的ContentPage中添加ContentView时遇到了一些麻烦,
我已按照教程:Xamarin Forms - How to display content from one xaml inside another
但没有运气。
以下是我要添加的contentView的代码:
<?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>
这是我要添加内容视图的内容页面:
<?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>
我正在尝试使用“local:view_evento”调用内容视图,但在运行时我什么都没看到,有什么建议吗?
感谢。