xamarin.forms add switch in toolbar

不问归期 提交于 2021-02-07 10:19:05

问题


Is it possible to add a switch on the toolbar?

<ContentPage.ToolbarItems>
    <ToolbarItem>
        <Switch x:Name="Switch1" IsToggled="True" Margin="5,0,0,0"/>
    </ToolbarItem>    
</ContentPage.ToolbarItems>

Does anybody have any ideas?

Thanks!


回答1:


<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:TitleViewSample"
             x:Class="TitleViewSample.MainPage">

    <NavigationPage.TitleView>
             <Switch x:Name="Switch1" IsToggled="True" Margin="5,0,0,0"/>
    </NavigationPage.TitleView>

    <ContentPage.Content>    
        <StackLayout>
            <!-- Place new controls here -->
            <Label Text="Welcome to Xamarin.Forms!" 
            HorizontalOptions="Center"
            VerticalOptions="CenterAndExpand" />
        </StackLayout>
    </ContentPage.Content>

</ContentPage>



回答2:


I don't think it is possible. You can, however, take the same approach I did when I needed to customise my title bar.

First, you hide the navigation bar, then you can specify your bar at the top, and use the controls you would like.



来源:https://stackoverflow.com/questions/52390358/xamarin-forms-add-switch-in-toolbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!