Skip to content

Instantly share code, notes, and snippets.

View TheBaileyBrew's full-sized avatar
⌨️
Coding

TheBaileyBrew TheBaileyBrew

⌨️
Coding
  • Grand Rapids, MI
View GitHub Profile
<Shell.FlyoutHeaderTemplate>
<DataTemplate>
<yummy:PancakeView
BackgroundGradientAngle="0"
BackgroundGradientEndColor="{StaticResource flyoutGradientEndFaded}"
BackgroundGradientStartColor="{StaticResource flyoutGradientStartFaded}"
HorizontalOptions="FillAndExpand"
IsClippedToBounds="true"
VerticalOptions="FillAndExpand">
<StackLayout Margin="0,10,0,0" Padding="25">
<FlyoutItem
Title="Item Search"
FlyoutDisplayOptions="AsSingleItem"
Route="Items_Search">
<Tab Title="Item Search" Route="item_search">
<ShellContent
Title="Item Search"
ContentTemplate="{DataTemplate local:ItemSearchPage}"
Route="item_search" />
</Tab>
<FlyoutItem
Title="Items"
FlyoutDisplayOptions="AsSingleItem"
Route="Header_Items" />
protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
{
// Returning something like this will look at the route declaration and determine if it's a header or item
return ((FlyoutItem)item).Route.StartsWith("Header") ? NavigationHeaderTemplate : NavigationItemTemplate;
}
<Shell
...
ItemTemplate="{StaticResource FlyoutTemplateSelector}"
... >
<Style x:Key="FlyoutHeaderStyle" TargetType="Label">
<Setter Property="FontSize" Value="Default" />
<Setter Property="Margin" Value="15,0" />
<Setter Property="TextColor" Value="Black" />
<Setter Property="FontAttributes" Value="Bold" />
<Setter Property="HorizontalOptions" Value="Start" />
</Style>
<Style x:Key="FlyoutItemStyle" TargetType="Label">
<Setter Property="FontSize" Value="Default" />
public class NavigationFlyoutItemTemplateSelector : DataTemplateSelector
{
public DataTemplate NavigationHeaderTemplate { get; set; }
public DataTemplate NavigationItemTemplate { get; set; }
protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
{
//Returning null, because at this point I'm not sure how to select the correct template
return null;
}
<Shell.ItemTemplate>
<DataTemplate>
<ContentView>
Bindable Properties: Title, Icon
</ContentView>
</DataTemplate>
</Shell.ItemTemplate>
@TheBaileyBrew
TheBaileyBrew / ShellFlyoutCreation
Created June 5, 2019 19:40
Creating FlyoutItems Dynamically in Xamarin.Forms Shell
//I actually have this separated out into a model class, but it could technically be internal like this
internal class NavigationItem {
public string Title { get; set; } ////This pairs with ShellItem.Title
public DataTemplate Template { get; set; } ////This pairs with ShellItem.ContentTemplate
public ImageSource Image { get; set; } ////This pairs with ShellItem.Icon
public string Route { get; set; } ////This pairs with ShellItem.Route
public List<ShellContent> Tabs { get; set; } ////This pairs with ShellItem.Tab
public bool HasImage => Image != null; ////These are optional, and just for validation purpose
public bool HasNavigation => Template != null; ////These are optional, and just for validation purpose
if (mCurrentBookUri == null) {
Toast.makeText(this,getString(R.string.not_save_msg), Toast.LENGTH_SHORT).show();
}
if (TextUtils.isEmpty(nameString)){
Toast.makeText(this, getString(R.string.enter_name_req),Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(priceString)){
Toast.makeText(this, getString(R.string.enter_price_req),Toast.LENGTH_SHORT).show();
return;