Maui: [Spec] AppBar

Created on 18 Jun 2020  路  6Comments  路  Source: dotnet/maui

AppBar

An app bar consists of a toolbar and potentially other views. Expose one or more actions.

The main benefit of using the appbar is being able to customize everything. Customization options like:

  • Custom app bar height.
  • Include any content without restrictions or limitations (margins, size, etc.).
  • Transparent appbar.
  • Etc.

NOTE: AppBar is a cross-platform view that takes over when native navbar hit their limits, such as adding custom content, positioning with layouts, etc.

In Xamarin.Forms, the app bar are typically used in the Shell.AppBar property, which places the app bar as a fixed-height widget at the top of the screen.

appbar

API

Next, a list with the AppBar properties and events.

Properties

| Property | Type | Description |
|----------|:-------------:|:-------------:|
| Placement | AppBarPlacement | The AppBar placement (top or bottom). |
| BarHeight | double | Define the app bar height. |
| BarBackground | Brush | A brush that provides the background. |
| BarBackgroundImage | ImageSource | An ImageSource that provides the background. |
| BarTextColor | Color | The color used in the texts (title, etc.). |
| NavigationIcon | ImageSource | An ImageSource that provides the navigation icon (back button, etc). |
| BackButtonTitle | string | Define the app bar back button title. |
| BorderColor | Color | The app bar border color. |
| BorderThickness | Thickness | The appbar border width in every side. |
| FontFamily | string | The font family used in the app bar texts. |
| FontAttributes | FontAttributes | The font attributes used in the app bar texts. |
| FontSize | double | The font size used in the app bar texts. |
| TitleView | View | Display any Xamarin.Forms View in the app bar. |
| BackCommand | ICommand | Command executed navigating back. |
| BackCommandParameter | object | The command parameter used navigating back. |

Events

| Event | Description |
|----------|:-------------:|
| BackTapped | Event that is raised when the user navigate back. |

Scenarios

Let's see some samples covering common scenarios.

Simple app bar

Let's see a basic example:

<Shell>
     <Shell.AppBar>
         <AppBar />
     </Shell.AppBar>
    ...
</Shell>

Custom app bar

Customizing the appearance using a transparent bar with a custom height and custom content (TitleView).

<Shell>
     <Shell.AppBar>
        <AppBar  
            BarHeight="120"
            BarBackgroundColor="Transparent">
            <AppBar.TitleView>
            ...
            </AppBar.TitleView>
        </AppBar>
     </Shell.AppBar>
    ...
</Shell>

Placement

A top app bar (default placement) displays navigation and actions at the top of mobile screens.

<Shell>
     <Shell.AppBar
          Placement="Top">
         <AppBar />
     </Shell.AppBar>
    ...
</Shell>

appbar-top

A bottom app bar displays navigation and actions at the bottom of mobile screens.

<Shell>
     <Shell.AppBar
          Placement="Bottom">
         <AppBar />
     </Shell.AppBar>
    ...
</Shell>

appbar-bottom

Using Styles

Can customize the appearance of the tab content, tab strip, tab item, etc. using XAML styles or CSS.

Using XAML:

<Style
    x:Key="AppBarStyle"
    TargetType="AppBar">
    <Setter
        Property="BarHeight"
        Value="120" />
    <Setter
        Property="BarBackgroundColor"
        Value="Transparent" />
</Style>

Using CSS:

.appBarStyle {
  background: transparent;
  height: 120px;
}

Difficulty : Medium

More information

Based on https://github.com/xamarin/Xamarin.Forms/issues/10774

proposal-open

Most helpful comment

Please manage and, i think prioritize, support for the standard navigation page!!
Not all use Shell's navigation, mostly Enterprise Application or Big Application based on Xamarin Forms!!

Thanks!!

All 6 comments

Please manage and, i think prioritize, support for the standard navigation page!!
Not all use Shell's navigation, mostly Enterprise Application or Big Application based on Xamarin Forms!!

Thanks!!

Yes, I would love to use this control and have apps pre Shell that would be difficult to convert to shell

It's just a composite Forms View

You could use it as a cell for a CollectionView and have an infinite number of AppBars

Why not View type instead of String in things like: BackButtonTitle?

These are moving to Xamarin Community Toolkit for now

@PureWeen How it is gonna work? I don't see an opened Issue for AppBar in Xamarin Community Toolkit repo.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PureWeen picture PureWeen  路  21Comments

qcjxberin picture qcjxberin  路  5Comments

adojck picture adojck  路  15Comments

Joshua-Ashton picture Joshua-Ashton  路  9Comments

Suplanus picture Suplanus  路  4Comments