Xamarin.forms 如何在选项卡式页面的导航栏中添加搜索栏

Xamarin.forms 如何在选项卡式页面的导航栏中添加搜索栏,xamarin.forms,navigationbar,searchbar,tabbedpage,Xamarin.forms,Navigationbar,Searchbar,Tabbedpage,我用的是xamarin。表单应用程序,其中导航栏中将有两个带有搜索图标的选项卡。我想在这里实现的是,当点击搜索图标时,所有导航栏和选项卡都应该消失,并打开与当前选项卡相关的搜索栏 示例:最初,页面类似于 点击搜索图标时,我希望视图如下所示 如何实现它?您可以使用Xamarin的最新版本实现选项卡式页面布局 请参阅以下代码结构: AppShell.Xaml <?xml version="1.0" encoding="UTF-8"?> <Shell xmlns="http://

我用的是xamarin。表单应用程序,其中导航栏中将有两个带有搜索图标的选项卡。我想在这里实现的是,当点击搜索图标时,所有导航栏和选项卡都应该消失,并打开与当前选项卡相关的搜索栏

示例:最初,页面类似于

点击搜索图标时,我希望视图如下所示


如何实现它?

您可以使用Xamarin的最新版本实现选项卡式页面布局

请参阅以下代码结构:

AppShell.Xaml

<?xml version="1.0" encoding="UTF-8"?>
<Shell xmlns="http://xamarin.com/schemas/2014/forms" 
       xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
       xmlns:views="clr-namespace:ProjectName.Views"
       x:Class="ProjectName.AppShell">
    <Tab>
        <ShellContent 
                      Title="Page1"
                      ContentTemplate="{DataTemplate views:Page1}" />
        <ShellContent 
                      Title="Page2"
                      ContentTemplate="{DataTemplate views:Page2}" />
    </Tab>
</Shell>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
             x:Class="ProjectName.Views.Page1" 
             Title="Page1">

   <Shell.SearchHandler>
      <SearchHandler Placeholder="Enter search term"/>
   </Shell.SearchHandler>

   <ContentPage.Content>
      <!--Get you desired content here-->
   </ContentPage.Content>

</ContentPage>

Page1.Xaml

<?xml version="1.0" encoding="UTF-8"?>
<Shell xmlns="http://xamarin.com/schemas/2014/forms" 
       xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
       xmlns:views="clr-namespace:ProjectName.Views"
       x:Class="ProjectName.AppShell">
    <Tab>
        <ShellContent 
                      Title="Page1"
                      ContentTemplate="{DataTemplate views:Page1}" />
        <ShellContent 
                      Title="Page2"
                      ContentTemplate="{DataTemplate views:Page2}" />
    </Tab>
</Shell>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
             x:Class="ProjectName.Views.Page1" 
             Title="Page1">

   <Shell.SearchHandler>
      <SearchHandler Placeholder="Enter search term"/>
   </Shell.SearchHandler>

   <ContentPage.Content>
      <!--Get you desired content here-->
   </ContentPage.Content>

</ContentPage>

输出:


Hi@Himanshu Dwivedi,对不起,您的解决方案不符合我的要求,因为我希望在单击搜索图标时,这些选项卡也必须隐藏。恐怕您必须自己编写布局。您不能简单地通过shell或naviagtionbar实现它。