English 中文(简体)
How to customize flyout page top bar in xamarin forms
原标题:

I want to customize top bar of Xamarin forms like following i want to add some of menus search-bar and profile icon with drop down example image is here

I am trying to achieve this with flyoutpage control.

Please help me to achieve the result first

问题回答

You can try to use NavigationPage.TitleView to achieve this. Remember to remove the Title of the ContentPage.

Please refer to the following code:

<?xml version="1.0" encoding="UTF-8"?> 
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
                   xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
                   x:Class="FlyoutPageNavigation.ContactsPage"
                  >

    <NavigationPage.TitleView >
        <StackLayout Orientation="Horizontal"  HorizontalOptions="FillAndExpand"  VerticalOptions="CenterAndExpand" MinimumWidthRequest="200">
            <Label Text="test"  Margin="10,0,10,0"></Label>
            <SearchBar Text="please input key words" BackgroundColor="Yellow" HorizontalOptions="FillAndExpand"    ></SearchBar>
        </StackLayout>
    </NavigationPage.TitleView>
      <ContentPage.Content>
            <StackLayout>
                  <Label Text="Contacts data goes here" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" />
            </StackLayout>
      </ContentPage.Content>
</ContentPage>

Update:

i want the common titleview for all. It will take a while for me to do for all pages.

You can create common contentview for all the pages.

1.create a ContentView (CustomTitleView)

<?xml version="1.0" encoding="UTF-8"?> 
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="FlyoutPageNavigation.CustomTitleView">
  <ContentView.Content>
        <StackLayout Orientation="Horizontal"  HorizontalOptions="FillAndExpand"  VerticalOptions="CenterAndExpand" MinimumWidthRequest="200">
            <Label Text="custom contentview"   Margin="10,0,10,0"></Label>
            <SearchBar Text=" key words" BackgroundColor="Yellow" HorizontalOptions="FillAndExpand"    ></SearchBar>
        </StackLayout>
    </ContentView.Content>
</ContentView>

2.add this CustomTitleView to Application.Resources of file App.xaml

<?xml version="1.0" encoding="utf-8" ?> 
<Application xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
             xmlns:flyoutpagenavigation="clr-namespace:FlyoutPageNavigation"
             x:Class="FlyoutPageNavigation.App">
    <Application.Resources>
        <flyoutpagenavigation:CustomTitleView x:Key="CustomTitleView"/>

        <Style TargetType="ContentPage" x:Key="CustomPage">
            <Setter Property="NavigationPage.TitleView" Value="{StaticResource CustomTitleView}"/>
        </Style>

    </Application.Resources>
</Application>

3.add Style="{StaticResource CustomPage}" to all pages:

For example:

<?xml version="1.0" encoding="UTF-8"?> 
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
                   xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
                   x:Class="FlyoutPageNavigation.ContactsPage"
             
                 Style="{StaticResource CustomPage}"
                  >

    <ContentPage.Content>
            <StackLayout>
                  <Label Text="Hi" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" />
            </StackLayout>
      </ContentPage.Content>
</ContentPage>




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签