我正在尝试添加在 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:
我的目标是 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/