![](/img/trans.png)
[英]Custom EventHandler in Xamarin.Forms doesn't work in xaml
[英]Android native view in xaml doesn't display in Xamarin.Forms
我正在嘗試添加在 xaml 中聲明的 Android 本機視圖 (Android.Widgets.TextView)。 我在這里關注 Xamarin 文檔。
然而,帶有本機視圖的 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>
和智能感知:
我的目標是 Xamarin.Forms 包 v2.3.4.247。 任何想法為什么它不顯示本機視圖?
刪除后面代碼中的 Xaml 編譯
//[XamlCompilation(XamlCompilationOptions.Compile)]
沒有這個,你的原生視圖就會出現。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.