Xamarin表单:未显示浮动操作按钮

时间:2017-02-10 08:08:31

标签: c# xamarin.forms

我正在尝试在我的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>

1 个答案:

答案 0 :(得分:0)

您需要将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);
    }