【问题标题】:xamarin.forms add switch in toolbarxamarin.forms 在工具栏中添加开关
【发布时间】:2018-09-18 15:50:47
【问题描述】:

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

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

有人有什么想法吗?

谢谢!

【问题讨论】:

    标签: xamarin.forms switch-statement toolbar uiswitch


    【解决方案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>
    

    【讨论】:

    • 谢谢你试试看。
    • NavigationPage 是从哪里来的?你是说内容页吗?
    • 在创建应用程序时未将主页面设置为导航页(Application.Current.MainPage = new NavigationPage(new PageName()); ),无法获取导航栏。如果你有一个初始化的导航页面,你可以得到导航栏,你可以自定义它。
    • 好的,我会检查这个。谢谢。
    【解决方案2】:

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

    首先,您隐藏导航栏,然后您可以在顶部指定您的导航栏,并使用您想要的控件。

    【讨论】:

    • 那太棒了。您能否制作一个代码示例来说明这是如何实现的?
    猜你喜欢
    • 2018-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多