Tony Lugg
Tony Lugg

Reputation: 572

Xamarin Forms Shell Flyout with Different Title on Tab

I'm making the move from traditional navigation to Shell. Is it possible to have different text on the flyout items vs the tabs? The tab text needs to be short where the flyout could be more descript.

For example, I may have Call for Assistance as the title of the flyout item, but just Call for the tab.

Upvotes: 0

Views: 400

Answers (1)

Leo Zhu
Leo Zhu

Reputation: 15001

If you want to achieve this effect,you could define FlyoutItem appearance,customize it by setting the Shell.ItemTemplate attached property to a DataTemplate,then let your Label Binding Value Converters to convert the title string:

like:

<Shell>
   ...
  <Shell.Resources>
      <ResourceDictionary>
         <local:TitlleConverter x:Key="titleConverter" />
      </ResourceDictionary>
  </Shell.Resources>

  <Shell.ItemTemplate>
    <DataTemplate>
            <Label 
                   Text="{Binding Title,Converter= {StaticResource titleConverter}}"
                   FontAttributes="Italic"
                   VerticalTextAlignment="Center"  />   
    </DataTemplate>
  </Shell.ItemTemplate>   
   
  <FlyoutItem>         
     <ShellContent  Titile ="Call" />
     <ShellContent  Titile ="" />
     <ShellContent  Titile ="" />
  </FlyoutItem>
</Shell>

the TitlleConverter.cs :

class TitlleConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (!string.IsNullOrEmpty((string)value) && value.Equals("Call"))
        {
            return "Call for Assistance";
        }
        return value;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

Upvotes: 1

Related Questions