Asp.net mvc 如何在导航页面中包含搜索栏

Asp.net mvc 如何在导航页面中包含搜索栏,asp.net-mvc,xamarin.forms,xamarin.android,searchbar,android-navigation-bar,Asp.net Mvc,Xamarin.forms,Xamarin.android,Searchbar,Android Navigation Bar,所以,我需要在导航页面或导航栏中包含搜索栏,但我不明白如何通过编程实现这一点。我可以在App.cs中创建搜索栏,但不能将其包含在导航栏中(我在ASp.NetCore中处理Xamarin.Forms和RestApi。请帮助我 受保护的异步重写void OnStart(){ HttpResponseMessage response=await client.GetAsync(“http://192.168.1.6:5000/api/Events"); if(response.StatusCode=

所以,我需要在导航页面或导航栏中包含搜索栏,但我不明白如何通过编程实现这一点。我可以在App.cs中创建搜索栏,但不能将其包含在导航栏中(我在ASp.NetCore中处理Xamarin.Forms和RestApi。请帮助我

受保护的异步重写void OnStart(){
HttpResponseMessage response=await client.GetAsync(“http://192.168.1.6:5000/api/Events");
if(response.StatusCode==HttpStatusCode.OK)
{
HttpContent responseContent=response.Content;
var json=await responseContent.ReadAsStringAsync();
List Events=JsonConvert.DeserializeObject(json);
主页页=新主页页();
StackLayout MyButtons=新建StackLayout()
{
方向=堆叠方向。垂直,
HorizontalOptions=LayoutOptions.FillAndExpand,
};
搜索栏搜索=新建搜索栏
{
占位符=“搜索项目…”,
占位符颜色=颜色。灰色,
text颜色=颜色。灰色,
HorizontalTextAlignment=TextAlignment.End,
水平选项=布局选项。中心,
垂直选项=布局选项。开始,
FontSize=Device.GetNamedSize(NamedSize.Medium,typeof(SearchBar)),
FontAttributes=FontAttributes.Italic,
};
search.SearchButtonPressed+=OnSearchButtonPressed;
框架搜索=新框架()
{
边框颜色=颜色。灰色,
转弯半径=10,
水平选项=布局选项。中心,
垂直选项=布局选项。开始,
HeightRequest=40,
宽度请求=180,
Hassadow=正确,
余量=新厚度(0,10,0,0),
填充=新厚度(0),
内容=新的堆栈布局
{
填充=0,
孩子们=
{
搜寻
}
}
};                
MyButtons.Children.Add(框架搜索);
foreach(事件中的变量项)
{
var btn=新按钮()
{
Text=item.Name,//无论你想把什么道具作为标题;
StyleId=item.EventId.ToString(),//使用事件中的属性作为要传递给处理程序的id
边界半径=50,
FontSize=30,
边框颜色=颜色。黑色,
FontAttributes=FontAttributes.Bold,
余量=新厚度(2,5,2,0),
填充=新厚度(0),
水平选项=LayoutOptions.FillAndExpand
};
btn.Clicked+=OnDynamicBtnClicked;
//Content=newcontentpage()
MyButtons.Children.Add(btn);
}
ScrollView ScrollView=新建ScrollView();
scrollView.Content=MyButtons;
page.Content=滚动视图;
Application.Current.MainPage=新导航页面(第页);
NavigationPage _Page=Application.Current.MainPage作为NavigationPage;
_Page.BarBackgroundColor=Color.FromHex(“009688”);
您可以设置以实现效果

就像在c代码中一样:

或在xaml中:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="NavigationPageTitleView.TitleViewPage">
  <NavigationPage.TitleView>
    <SearchBar HeightRequest="44" WidthRequest="300" />
  </NavigationPage.TitleView>
   ...
</ContentPage>     

...

能用吗?是吗?谢谢!))
public TitleViewPage()
    {
        InitializeComponent();
        var titleView = new SearchBar { HeightRequest = 44, WidthRequest = 300 };
        NavigationPage.SetTitleView(this, titleView);
    }
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="NavigationPageTitleView.TitleViewPage">
  <NavigationPage.TitleView>
    <SearchBar HeightRequest="44" WidthRequest="300" />
  </NavigationPage.TitleView>
   ...
</ContentPage>