Xamarin表单:未显示浮动操作按钮
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Xamarin表单:未显示浮动操作按钮相关的知识,希望对你有一定的参考价值。
我试图在我的xamarin表单项目中显示浮动操作按钮。我使用以下xaml文件,Button没有显示,但我不明白为什么。请帮我解决这个问题。我正在使用FAB.FORMS库来显示浮动操作按钮:
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:fab="clr-namespace:FAB.Forms;assembly=FAB.Forms"
x:Class="iFocusDiscussionForum.PostList" Title="Discussion List" >
<ContentPage.Content>
<RelativeLayout>
<ContentView
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1}">
<ListView x:Name="listview" RowHeight="120" ItemSelected = "OnItemSelected">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="5" Margin="5">
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentView>
<fab:FloatingActionButton
Source = "plus.png"
Clicked = "Handle_Clicked"
Size="Normal"
RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1, Constant=-60}"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1, Constant=-60}"/>
<!--<StackLayout HorizontalOptions="End" VerticalOptions="End" BackgroundColor="#F4F5F8">
<fab:FloatingActionButton x:Name="testing" Image="plus.png" Clicked="testingClicked" BackgroundColor="#F4F5F8" BorderColor="Transparent" />
</StackLayout>-->
</RelativeLayout>
</ContentPage.Content>
</ContentPage>
答案
您需要将FloatingActionButtonRenderer.InitControl();
添加到AppDelegate.cs中
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
Plugin.Iconize.Iconize.With(new Plugin.Iconize.Fonts.FontAwesomeModule());
ImageCircleRenderer.Init();
TintedImageRenderer.Init();
FloatingActionButtonRenderer.InitControl();
LoadApplication(new App());
return base.FinishedLaunching(app, options);
}
以上是关于Xamarin表单:未显示浮动操作按钮的主要内容,如果未能解决你的问题,请参考以下文章
浮动操作按钮未显示在 recyclerview 上(位于 DrawerLayout 内)