简体   繁体   English

xaml 中的 Android 本机视图不会显示在 Xamarin.Forms 中

[英]Android native view in xaml doesn't display in Xamarin.Forms

I'm trying at add an Android native view (Android.Widgets.TextView) declared in xaml.我正在尝试添加在 xaml 中声明的 Android 本机视图 (Android.Widgets.TextView)。 I was following the Xamarin documentation here . 我在这里关注 Xamarin 文档

However Intelisense in the xaml file with the native view shows Android.Widget and Xamarin.Forms namespaces don't exist.然而,带有本机视图的 xaml 文件中的 Intelisense 显示 Android.Widget 和 Xamarin.Forms 命名空间不存在。 When I run the app everything run's without crashing or any errors in the debug output but the Android.Widgets.TextView does not display.当我运行应用程序时,一切运行都没有崩溃或调试输出中的任何错误,但 Android.Widgets.TextView 不显示。 I tried a new page and copy and pasted the example from the link above but had the same issues.我尝试了一个新页面并复制并粘贴了上面链接中的示例,但遇到了同样的问题。

Here is my Xaml:这是我的 Xaml:

<?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="CrucialExams.Xamarin.Views.FlashCardsPage"
             xmlns:controls="clr-namespace:CarouselView.FormsPlugin.Abstractions;assembly=CarouselView.FormsPlugin.Abstractions"
             xmlns:views="clr-namespace:CrucialExams.Xamarin.Views;assembly=CrucialExams.Xamarin" 
             xmlns:androidWidget="clr-namespace:Android.Widget;assembly=Mono.Android;targetPlatform=Android"
             xmlns:formsAndroid="clr-namespace:Xamarin.Forms;assembly=Xamarin.Forms.Platform.Android;targetPlatform=Android"
             Title="{Binding Title}"
             BackgroundColor="{StaticResource LightBackgroundColor}"
             Padding="0">
    <ContentPage.Content>
        <androidWidget:TextView Text="Native Text" x:Arguments="{x:Static formsAndroid:Forms.Context}" />
        <Grid Margin="3" Padding="5">
        <Grid.RowDefinitions>
            <RowDefinition Height="1*" />
            <RowDefinition Height="9*" />
        </Grid.RowDefinitions>
            <!--<views:PercentageBarView BackgroundColor="Red" Grid.Row="0"></views:PercentageBarView>-->
            <controls:CarouselViewControl   Grid.Row="1"
                                        x:Name="Carousel"
                                        Margin="0"
                                        Position="0" 
                                        ItemsSource="{Binding Pages}" 
                                        VerticalOptions="FillAndExpand" 
                                        HorizontalOptions="FillAndExpand">
            <controls:CarouselViewControl.ItemTemplate>
                <DataTemplate>
                    <Grid Margin="3" Padding="5">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="10*" />
                        </Grid.RowDefinitions>
                        <Frame HasShadow="True" Margin="5" Grid.Row="0">
                            <Frame.GestureRecognizers>
                                <TapGestureRecognizer Tapped="OnCardTapped"/>
                            </Frame.GestureRecognizers>
                            <Label  Margin="5" 
                                    FontSize="25" 
                                    Text="{Binding CurrentText}" 
                                    HorizontalTextAlignment="Center" 
                                    VerticalTextAlignment="Center" />
                        </Frame>
                    </Grid>
                </DataTemplate>
            </controls:CarouselViewControl.ItemTemplate>
        </controls:CarouselViewControl>
        </Grid>
    </ContentPage.Content>
</ContentPage>

And Intelisense:和智能感知:

在此处输入图片说明

I'm targeting Xamarin.Forms package v2.3.4.247.我的目标是 Xamarin.Forms 包 v2.3.4.247。 Any ideas why it's not showing the native view?任何想法为什么它不显示本机视图?

Remove Xaml Compilation in your code behind删除后面代码中的 Xaml 编译

//[XamlCompilation(XamlCompilationOptions.Compile)]

Without this, your native view will appear.没有这个,你的原生视图就会出现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM