c# - Xaml 中的 Android native View 不显示在 Xamarin.Forms 中

标签 c# xaml xamarin xamarin.android xamarin.forms

我正在尝试添加在 xaml 中声明的 Android native View (Android.Widgets.TextView)。 I was following the Xamarin documentation here .

但是,带有 native View 的 xaml 文件中的 Intelisense 显示 Android.Widget 和 Xamarin.Forms 命名空间不存在。当我运行应用程序时,一切都在运行,没有崩溃或调试输出中有任何错误,但 Android.Widgets.TextView 不显示。我尝试了一个新页面并复制并粘贴了上面链接中的示例,但遇到了同样的问题。

这是我的 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>

和 Intelisense:

enter image description here

我的目标是 Xamarin.Forms 包 v2.3.4.247。为什么它不显示 native View 有什么想法吗?

最佳答案

移除代码中的 Xaml 编译

//[XamlCompilation(XamlCompilationOptions.Compile)]

没有这个,你的原生 View 就会出现。

关于c# - Xaml 中的 Android native View 不显示在 Xamarin.Forms 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45112446/

相关文章:

c# - SQL Server 应用程序 - 将数据库重置为原始状态

c# - 如何提高大量较小文件的读写速度或性能

c# - winforms中拦截OnKeyPress事件后OnKeyUp不触发

Xamarin 自定义控件,如何添加要在 Xcode 面板中显示的属性?

android - 保存 pdf 而不向用户显示打印对话屏幕

c# - Linq 表达式返回 null

c# - 在 SL ComboBox 上使用 CollectionView 刷新时 SelectedItemIndex 不匹配

c# - SHIFT + 滚动可在 ScrollViewer UWP 中水平滚动

javascript - 修改Webview控件中传输的数据

c# - 在 xaml 4.5+ 中创建通用列表