Skip to content

Instantly share code, notes, and snippets.

@JerryNixon
Created September 15, 2018 01:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JerryNixon/c797538f9c3e4e5c4c1039354020c05f to your computer and use it in GitHub Desktop.
Save JerryNixon/c797538f9c3e4e5c4c1039354020c05f to your computer and use it in GitHub Desktop.
[ContentProperty(Name = nameof(LiteralContent))]
public sealed class AppBarLiteral : AppBarSeparator
{
public AppBarLiteral()
{
DefaultStyleKey = typeof(AppBarLiteral);
}
public object LiteralContent
{
get { return (object)GetValue(LiteralContentProperty); }
set { SetValue(LiteralContentProperty, value); }
}
public static readonly DependencyProperty LiteralContentProperty =
DependencyProperty.Register(nameof(LiteralContent), typeof(object),
typeof(AppBarLiteral), new PropertyMetadata(null));
}
@JerryNixon
Copy link
Author

JerryNixon commented Sep 15, 2018

This goes in your \Themes\generic.xaml file.

you will need to change the xmlns:local path to your app's namespace.

<ResourceDictionary
    xmlns:local="using:Sample.Controls"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">

    <Style TargetType="local:AppBarLiteral">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:AppBarLiteral">
                    <ContentPresenter Content="{TemplateBinding LiteralContent}" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
</ResourceDictionary>

This is what it looks like.

image

This is how you use it in your app.

<Page.TopAppBar>
    <CommandBar IsDynamicOverflowEnabled="False">
        <CommandBar.Content>
            <TextBlock Text="Star Trek" VerticalAlignment="Center" Margin="16,8,0,0" 
                        Style="{StaticResource TitleTextBlockStyle}" />
        </CommandBar.Content>
        <controls:AppBarLiteral>
            <AutoSuggestBox QueryIcon="Find" PlaceholderText="Search" Width="250" Margin="0,8,4,0"
                            Text="{x:Bind ViewModel.SearchString, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
        </controls:AppBarLiteral>
        <AppBarButton Label="Info" Icon="World" AccessKey="i" />
    </CommandBar>
</Page.TopAppBar>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment