xamarin.forms在工具栏中添加开关

xamarin.forms在工具栏中添加开关,xamarin.forms,switch-statement,toolbar,uiswitch,Xamarin.forms,Switch Statement,Toolbar,Uiswitch,是否可以在工具栏上添加开关 <ContentPage.ToolbarItems> <ToolbarItem> <Switch x:Name="Switch1" IsToggled="True" Margin="5,0,0,0"/> </ToolbarItem> </ContentPage.ToolbarItems> 有人有什么想法吗 谢谢 我认为这是不可能的。但是,您可以采用与我在需要自定义

是否可以在工具栏上添加开关

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

有人有什么想法吗


谢谢

我认为这是不可能的。但是,您可以采用与我在需要自定义标题栏时相同的方法

首先,隐藏导航栏,然后在顶部指定导航栏,并使用所需的控件。


<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>

那太棒了。你能做一个代码示例说明这是如何实现的吗?谢谢,我会尝试一下。NavigationPage是从哪里来的?你是说contentpage吗?如果创建应用程序时未将主页设置为导航页(application.Current.MainPage=new-NavigationPage(new-PageName());),则无法获取导航栏。如果你有一个初始化的导航页面,你可以得到导航栏,你可以自定义它。好的,我会检查这个。谢谢