<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Coding &lt;Notes/&gt;</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/juanmejia/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/juanmejia/feed.xml</link>
    <description>Tips &amp;amp; samples on  UWP, Azure and WPF</description>
    <lastBuildDate>Wed, 17 Apr 2019 03:40:06 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Icon Fonts in UWP Apps</title>
      <link>https://docs.microsoft.com/archive/blogs/juanmejia/icon-fonts-in-uwp-apps</link>
      <pubDate>Tue, 26 Dec 2017 16:09:11 GMT</pubDate>
      <dc:creator><![CDATA[Juan Mejia Velez]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/juanmejia/?p=505</guid>
      <description><![CDATA[Icons are an essential element for graphical user interfaces. They allow intuitive actions by users,...]]></description>
      <content:encoded><![CDATA[<div class="x-text-justified">Icons are an essential element for graphical user interfaces. They allow intuitive actions by users, provide space optimization (e.g. Toolbars), create better mnemonics around app’s functionality, among other things that go beyond the goal for this post. In summary, they are nice to have in our apps, but with proper use. Too much of something good leads to bad results.</div>

<!--more-->

<div class="x-text-justified">Methods to load iconographic assets in apps have improved over the years. A great advantage to those who do not have the support of graphical designers on their teams. Icons for apps have evolved from old day clip-art galleries all the way to icons stored inside font files. This latest method besides being handy provides the ability to render vectorized icons. <em class="x-emphasis-cursive">Vectors</em> adapt themselves to different display resolutions where our app might be available. Most of the XAML visual elements are vectors and so should be icons.</div>
<div class="x-text-justified">Microsoft offers many fonts that ship with Windows containing illustration assets. From the traditional Wingdings fonts to the new ones designed for modern apps, the Segoe family of fonts. In the latest version of Windows 10, we can find <em class="x-emphasis-cursive">Segoe MDL2 Assets</em> and <em class="x-emphasis-cursive">Segoe UI Emoji</em>. They come preinstalled in the system and can be consumed by controls that render text simply by changing the <strong class="x-emphasis-bold">FontFamily</strong> property of the control. Although, there are a series of controls created to display icon assets.</div>
<div class="x-title-level1">Icon Classes</div>
<div class="x-image-right">

<img src="https://msdnshared.blob.core.windows.net/media/2017/12/image01.png" />
<div class="x-image-right-footer"><strong class="x-emphasis-bold">Image 1</strong> Character Map.</div>
</div>
<div class="x-text-justified">The UWP development platform provides a series of classes that extend the <a target="_blank" href="https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.iconelement" rel="noopener" class="x-link">IconElement</a> class, but only two of them support fonts as their source. <a target="_blank" href="https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.fonticon" rel="noopener" class="x-link">FontIcon</a> and <a target="_blank" href="https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.symbolicon" rel="noopener" class="x-link">SymbolIcon</a>, these classes differ in the way we indicate what icon to use. <em class="x-emphasis-cursive">SymbolIcon</em> is created exclusively to consume icons from Segoe MDL2 Assets, and its source can’t be changed. It allows the class to expose a <a target="_blank" href="https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.symbol" rel="noopener" class="x-link">Symbol</a> property that accepts an easy to memorize icon friendly name, as oppose to <em class="x-emphasis-cursive">FontIcon</em> where we can assign a different <em class="x-emphasis-cursive">FontFamily</em> value and indicate the icon to use through its <a target="_blank" href="https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.fonticon#Windows_UI_Xaml_Controls_FontIcon_Glyph" rel="noopener" class="x-link">Glyph</a> property using the internal Unicode value representing the glyph location inside the font file.</div>
<div class="x-text-justified">The value we can assign to the <em class="x-emphasis-cursive">Symbol</em> property in a <em class="x-emphasis-cursive">SymbolIcon</em> does not include the valid glyphs that the font provides. For those cases, the recommended method is to use the <em class="x-emphasis-cursive">FontIcon</em> class instead. We can freely indicate the Unicode value based on what the font contains. The two font icons that come with Windows usually get additional icons as new versions of Windows ship. For this reason, we need to be careful in assuming that a Unicode value will render a valid icon in the previous version of Windows where our app could be running as well. Check on <a target="_blank" href="https://docs.microsoft.com/en-us/windows/uwp/design/style/segoe-ui-symbol-font" rel="noopener" class="x-link">MSDN</a> or use the Character Map accessory application that comes with Windows to verify a Unicode value and if it is valid in the versions of Windows the app targets.</div>
<div class="x-text-justified">When using a Unicode value identified in the <em class="x-emphasis-cursive">Character Map</em> we use one of two formats based on where we make the assignment. In XAML code we use <strong class="x-emphasis-bold">"&#038;#xE787;"</strong> where <em class="x-emphasis-cursive">E787</em> is the hexadecimal value for the selected glyph in Character Map in image 1. To use it in code-behind the format is <strong class="x-emphasis-bold">"\uE787"</strong>.</div>
<div class="x-title-level1">Colorizing Icons</div>
<div class="x-image-left">

<img src="https://msdnshared.blob.core.windows.net/media/2017/12/image02.png" />
<div class="x-image-right-footer"><strong class="x-emphasis-bold">Image 2</strong> Overlapping icons with color.</div>
</div>
<div class="x-text-justified">The icons found in <em class="x-emphasis-cursive">Segoe UI Emoji</em> font come with color information for its glyphs. This color is shown if the platform or the application they are rendered in supports multicolor layers coming from fonts, UWP apps support it as well as Windows 10. In cases where there is no support for color, a monochromatic version of the emoji is displayed. Some text controls (<a target="_blank" href="https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.textblock" rel="noopener" class="x-link">TextBlock</a> and <a target="_blank" href="https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.textbox" rel="noopener" class="x-link">TextBox</a>) provide a property <strong class="x-emphasis-bold">IsColorFontEnabled</strong> to indicate when to use color or the fallback monochromatic version. <em class="x-emphasis-cursive">FontIcon</em> does not have this option. The glyphs found on <em class="x-emphasis-cursive">Segoe MDL2 Assets</em> are only monochromatic. There is no color information coming from the font itself, but that does not prevent us from setting the control’s <em class="x-emphasis-cursive">Foreground</em> property to some color and get the font’s glyphs colorized. If we look closely at all the glyphs provided by this font we will notice that certain icons come in two versions: <strong class="x-emphasis-bold">outline</strong> and <strong class="x-emphasis-bold">filled</strong>. Having a <em class="x-emphasis-cursive">FontIcon</em> instance rendering the fill glyph and assigning a color to its <em class="x-emphasis-cursive">Foreground</em> property, and overlapping another instance of <em class="x-emphasis-cursive">FontIcon</em> rendering the outline version of the icon creates the effect of multiple layers with different colors.</div>
<div class="x-title-level1">Custom Fonts</div>
<div class="x-text-justified">As seen in the previous section, there are instances where the icon we are looking for is not provided by any of the system fonts or that an icon does not have its corresponding outline/fill version we wish. To solve this, we could look for other fonts available online, free or commercial, and embed them into our project. Some projects might even have the budget to get professional font designer services where we could have fonts created with icons from trademarked visual assets, like logos or other visual assets that help our app set a differentiating element.</div>
<div class="x-image-right">

<img src="https://msdnshared.blob.core.windows.net/media/2017/12/image03.png" />
<div class="x-image-right-footer"><strong class="x-emphasis-bold">Image 3</strong> TrueTypeFont file embedded in project.</div>
</div>
<div class="x-text-justified">With a font file (usually TTF) that contains our custom icons embedded into the application project, we can proceed and use it in the different controls that we discussed earlier that support <em class="x-emphasis-cursive">FontFamily</em> changes. The same way as we add image files to the project we can add a font file. Verify that the file is added to the project with <em class="x-emphasis-cursive">Build Action</em> set to <em class="x-emphasis-cursive">Content</em>.</div>
<div class="x-text-justified">Once we have the file in the project is a matter of reference it in the <em class="x-emphasis-cursive">FontFamily</em> property of the control using this format:</div>
<pre><span style="color: #d769d8">FontFamily</span>=<span style="color: #2a3ee0">"[PathToTTF]#[NameOfFontFamily]"</span></pre>
<div class="x-text-justified">A font file could define more than one font family, for this reason, we need to indicate its name after the file name. On code-behind you can set this property as well, <a target="_blank" href="https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.media.fontfamily" rel="noopener" class="x-link">FontFamily</a> is a class that its constructor takes a string value indicating a Uri pointing to a resource. We can take this mechanism to refer to a custom font in our project this way.</div>

[sourcecode language="csharp" title="Definition of FontFamily in Code-Behind"]string fontFilePath = “ms-appx:///Assets/Fonts/MyCustomFont.ttf#My Personal Icons”;
fontIcon.FontFamily = new FontFamily(fontFilePath);[/sourcecode]

<div class="x-text-justified">Notice that the Uri uses the application Uri schema to refer to resources in a project. This provides the possibility to have font files embedded in satellite assemblies (Class Libraries).</div>

[sourcecode language="csharp" title="Definition of FontFamily in Class Library"]string assemblyName = GetType().GetTypeInfo().Assembly.GetName().Name;
string fontFamilyPath = $&quot;ms-appx:///{assemblyName}/Fonts/MyCustomFont.ttf#My Personal Icons&quot;);[/sourcecode]

<div class="x-title-level1">Final thoughts</div>
<div class="x-text-justified">Before closing this post, let’s talk about the user licenses that govern the use of fonts. The contents of fonts, being them letters or symbols, are bound to license that indicates if it is possible or not for us to redistribute the file with our application. It also indicates other permissions or restrictions regarding the modifications of the glyphs it contains.</div>
<div class="x-text-justified">A graphical designer or a company might have trademarked those designs an explicit permission should exist. In the case of the Segoe fonts or other fonts that are part of Windows 10, when we refer to their glyphs in our app without embedding the file in our project is part of the expected usage of it allowed by its license. We are not distributing the font and when the application is launched in a customer’s Windows 10 machine it will load the font information from that machine.</div>
<div class="x-text-justified">Same goes for any other font from the internet. We need to check what permissions or restrictions we must follow to make use of it.</div>
<div class="x-text-justified">In summary, we visited the icon controls that the platform offers as well as how to consume the system provided icons in those controls and a mechanism to include custom-made fonts embedded in our project or a class library.</div>]]></content:encoded>
    </item>
    <item>
      <title>Fluent Design on Ribbon-like Pivot</title>
      <link>https://docs.microsoft.com/archive/blogs/juanmejia/fluent-design-on-ribbon-like-pivot</link>
      <pubDate>Tue, 07 Nov 2017 11:07:23 GMT</pubDate>
      <dc:creator><![CDATA[Juan Mejia Velez]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/juanmejia/?p=465</guid>
      <description><![CDATA[Following up the article on Office Ribbon: Styling the Pivot Control, there were some remaining...]]></description>
      <content:encoded><![CDATA[<div class="x-text-justified">Following up the article on <a href="https://blogs.msdn.microsoft.com/juanmejia/2017/10/office-ribbon-styling-the-pivot-control/" target="_blank" class="x-link">Office Ribbon: Styling the Pivot Control</a>, there were some remaining visual effects that I kept thinking on how to implement to have a more closer experience to the one found on <em class="x-emphasis-cursive">Word Mobile</em>.</div>
<div class="x-text-justified">The light effect that appeared on nearby tab’s borders while hovering a tab was possible using a technique called <a href="https://docs.microsoft.com/en-us/windows/uwp/style/reveal" target="_blank" class="x-link">Reveal</a> from the <a href="https://fluent.microsoft.com/" target="_blank" class="x-link">Fluent Design System</a>, one of the new features of Windows 10 <em class="x-emphasis-cursive">Fall Creators Update</em>, which is about using light to guide user interaction into target areas of the app.</div>
<div class="x-text-justified">Some controls have this functionality baked into them but disabled by default as these visual effects are <em class="x-emphasis-cursive">GPU</em> intensive tasks that if used improperly or in too many controls could compromise the performance of your app altogether.</div>
<div class="x-text-justified">As many visual aspects this is achieved using styles paired with visual state changes. Another technique introduced by <em class="x-emphasis-cursive">Fluent Design</em> is <a href="https://docs.microsoft.com/en-us/windows/uwp/style/acrylic" target="_blank" class="x-link">Acrylic</a> which define a new <em class="x-emphasis-cursive">Brush</em> named <strong class="x-emphasis-bold">AcrylicBrush</strong> which allows different levels of transparency for app elements within the app and with other apps or objects behind its window.</div>
<div class="x-text-justified">The visual effects for <em class="x-emphasis-cursive">Reveal</em> combine a set of Brushes for Background, Foreground, and Border applied to the target element.</div>
<div class="x-image-right">
  <img src="https://msdnshared.blob.core.windows.net/media/2017/11/image01.png" />
  <div class="x-image-right-footer"><strong class="x-emphasis-bold">Image 1</strong> Project Target build.</div>
</div>
<div class="x-title-level1">Brushes</div>
<div class="x-text-justified">To be able to consume this feature we change the target values of the project to <em class="x-emphasis-cursive">Fall Creators Update</em> build in both values for build targets, this will make all the new types available to our code. There are ways to set up the code so that it checks for different build versions so that users in older builds can still run the app without the extra juice, but that is a topic for another post, so bear in mind that for this to work in your machine you need to have the Fall Creators Update and its SDK installed.</div>
<div class="x-text-justified">We begin defining two <em class="x-emphasis-cursive">AcrylicBrush</em> instances around the colors used in the <em class="x-emphasis-cursive">TitleBar</em> and the <em class="x-emphasis-cursive">PivotHeaderItem</em>. Then we create <strong class="x-emphasis-bold">StaticResource</strong> references to replace the values that were already used by the app.</div>
[sourcecode language="xml" title="AcrylicBrush definition for TitleBar in AppStyles.xaml" firstline="72"]&lt;AcrylicBrush x:Key=&quot;TitleBarAcrylicWindowBrush&quot;
              BackgroundSource=&quot;HostBackdrop&quot;
              TintColor=&quot;{StaticResource TitleBarBackgroundColor}&quot;
              TintOpacity=&quot;0.7&quot;
              FallbackColor=&quot;{StaticResource TitleBarBackgroundColor}&quot; /&gt;

&lt;StaticResource x:Key=&quot;TitleBarBackgroundColorBrush&quot; 
                ResourceKey=&quot;TitleBarAcrylicWindowBrush&quot; /&gt;[/sourcecode]

[sourcecode language="xml" title="AcrylicBrush definition for PivotHeaderItem in AppStyles.xaml" firstline="96"]&lt;AcrylicBrush x:Key=&quot;PivotHeaderItemAcrylicWindowBrush&quot;
              BackgroundSource=&quot;HostBackdrop&quot;
              TintColor=&quot;{StaticResource PivotHeaderBackgroundColor}&quot;
              TintOpacity=&quot;0.7&quot;
              FallbackColor=&quot;{StaticResource PivotHeaderBackgroundColor}&quot; /&gt;

&lt;StaticResource x:Key=&quot;PivotHeaderBackgroundColorBrush&quot; 
                ResourceKey=&quot;PivotHeaderItemAcrylicWindowBrush&quot; /&gt;[/sourcecode]

<div class="x-text-justified">If you read the previous article you might remember that we overrode a series of <em class="x-emphasis-cursive">StaticResource</em> references inside the <em class="x-emphasis-cursive">ThemeDictionary</em> to impact or affect those values inside the styles for <em class="x-emphasis-cursive">Pivot</em>, <em class="x-emphasis-cursive">PivotItem</em> and <em class="x-emphasis-cursive">PivotHeaderItem</em>. Pay closer attention to the later ones, they have combinations of states and actions to support the different <em class="x-emphasis-cursive">VisualState</em>s observed in the control’s behavior. To suit our new needs, we are going to rearchitect those references for <em class="x-emphasis-cursive">PivotHeaderItem</em> which is the area where we will be applying the <em class="x-emphasis-cursive">Reveal</em> effect.</div>
<div class="x-text-justified x-note"><strong>note:</strong> I am not paying extra attention and create the corresponding style values for the <em class="x-emphasis-cursive">HighContrast</em> and <em class="x-emphasis-cursive">Light</em> themes as you properly should for a real application, but this will clutter the code a bit and cause us to lose the focus on the concepts that are being pointed out in the articles.</div>
<div class="x-text-justified">The new changes organize the states and actions into three groups: Background, Foreground, and BorderBrush with the corresponding states of Selected and Unselected. Although the <em class="x-emphasis-cursive">“unselected”</em> is not part of the name for the resources anymore.</div>
<div class="x-text-justified">You can refer to the source code on <a href="https://github.com/JuanMejiaVelez/BlogSampleCode/" target="_blank" class="x-link">GitHub</a> to observe these changes as they represent a big chunk of code to include it in here.</div>

<div class="x-title-level1">Style Changes</div>
<div class="x-text-justified">Once all the colors and brushes are in place with the corresponding reference names for <em class="x-emphasis-cursive">StaticResources</em> we proceed to make modification inside the styles defined for the controls. Most of the changes were to the style for <em class="x-emphasis-cursive">PivotHeaderItem</em>, but a few improvements were given to the other styles as well that are worth mentioning. For the <em class="x-emphasis-cursive">Pivot</em> style, the <em class="x-emphasis-cursive">Background</em> property of the elements named <strong class="x-emphasis-bold">LeftHeaderPresenter</strong> and <strong class="x-emphasis-bold">RightHeaderPresenter</strong> is now pointing to a <em class="x-emphasis-cursive">ThemeResource</em> instead of a <em class="x-emphasis-cursive">StaticResource</em>, although the result is visually the same. Why this change? It is better for styles to have dependencies on values defined at a Theme-level, so they can adapt properly making the apps theme-aware. Another changed is around the <em class="x-emphasis-cursive">ItemsPresenter</em> named <strong class="x-emphasis-bold">PivotItemPresenter</strong>, this element has been wrapped in a <em class="x-emphasis-cursive">Grid</em>, so we can apply the properties of <em class="x-emphasis-cursive">Background</em>, <em class="x-emphasis-cursive">BorderBrush</em> and <em class="x-emphasis-cursive">BortherThickness</em> to the whole row. And the same values were removed from the root <em class="x-emphasis-cursive">Grid</em> on the <em class="x-emphasis-cursive">PivotItem</em>’s style <em class="x-emphasis-cursive">ControlTemplate</em>.</div>
[sourcecode language="xml" title="PivotItemPresenter in AppStyles.xaml" firstline="428" highlight="428,429,430,431,440"]&lt;Grid Grid.Row=&quot;1&quot; Grid.ColumnSpan=&quot;3&quot;
      Background=&quot;{ThemeResource PivotItemBackgroundColorBrush}&quot;
      BorderBrush=&quot;LightGray&quot;
      BorderThickness=&quot;0,0,0,1&quot;&gt;
  &lt;ItemsPresenter x:Name=&quot;PivotItemPresenter&quot;&gt;
    &lt;ItemsPresenter.RenderTransform&gt;
      &lt;TransformGroup&gt;
        &lt;TranslateTransform x:Name=&quot;ItemsPresenterTranslateTransform&quot; /&gt;
        &lt;CompositeTransform x:Name=&quot;ItemsPresenterCompositeTransform&quot; /&gt;
      &lt;/TransformGroup&gt;
    &lt;/ItemsPresenter.RenderTransform&gt;
  &lt;/ItemsPresenter&gt;
&lt;/Grid&gt;[/sourcecode]

<div class="x-text-justified">In the <em class="x-emphasis-cursive">PivotHeaderItem</em> style the changes made were on three areas as shown in the following code fragments, first to the <em class="x-emphasis-cursive">Style</em> setter properties some were modified, and others added.</div>

[sourcecode language="xml" title="Setters on PivotHeaderItem Style in AppStyles.xaml" firstline="491" highlight="493,494,496"]&lt;Setter Property=&quot;Background&quot; Value=&quot;{ThemeResource PivotHeaderItemBackground}&quot; /&gt;
&lt;Setter Property=&quot;Foreground&quot; Value=&quot;{ThemeResource PivotHeaderItemForeground}&quot; /&gt;
&lt;Setter Property=&quot;BorderBrush&quot; Value=&quot;{ThemeResource PivotHeaderItemBorderBrush}&quot; /&gt;
&lt;Setter Property=&quot;BorderThickness&quot; Value=&quot;{StaticResource PivotHeaderItemBorderThickness}&quot; /&gt;
&lt;Setter Property=&quot;Padding&quot; Value=&quot;{ThemeResource PivotHeaderItemMargin}&quot; /&gt;
&lt;Setter Property=&quot;UseSystemFocusVisuals&quot; Value=&quot;True&quot; /&gt;
&lt;Setter Property=&quot;Height&quot; Value=&quot;32&quot; /&gt;
[/sourcecode]

<div class="x-text-justified">Then some additional properties set on the <em class="x-emphasis-cursive">Grid</em> root for the <em class="x-emphasis-cursive">ControlTemplate</em>.</div>

[sourcecode language="xml" title="Root Grid for ControlTemplate in AppStyles.xaml" firstline="503"]&lt;Grid x:Name=&quot;Grid&quot;
      Background=&quot;{TemplateBinding Background}&quot;
      Padding=&quot;{TemplateBinding Padding}&quot;
      BorderBrush=&quot;{TemplateBinding BorderBrush}&quot;
      BorderThickness=&quot;{TemplateBinding BorderThickness}&quot;
      CornerRadius=&quot;{ThemeResource PivotHeaderItemCornerRadius}&quot;
      Control.IsTemplateFocusTarget=&quot;True&quot;&gt;
  [/sourcecode]

  <div class="x-text-justified">And as the core for the <em class="x-emphasis-cursive">Reveal</em> effect, the changes happened inside the <em class="x-emphasis-cursive">VisualState</em> elements for most of states in the controls behavior. As this code change is too big to post in here, I present one of them to illustrate the changes while the others are significantly similar with its corresponding resource value reference.</div>

[sourcecode language="xml" title="PivotItemPresenter in AppStyles.xaml" firstline="533" highlight="534,535,536,537,538,539,540,541,542"]&lt;VisualState x:Name=&quot;UnselectedPointerOver&quot;&gt;
  &lt;VisualState.Setters&gt;
    &lt;Setter Target=&quot;Grid.(RevealBrush.State)&quot; Value=&quot;PointerOver&quot; /&gt;
    &lt;Setter Target=&quot;Grid.Background&quot; 
            Value=&quot;{ThemeResource PivotHeaderItemBackgroundPointerOver}&quot; /&gt;
    &lt;Setter Target=&quot;Grid.BorderBrush&quot; 
            Value=&quot;{ThemeResource PivotHeaderItemBorderBrushPointerOver}&quot; /&gt;
    &lt;Setter Target=&quot;ContentPresenter.Foreground&quot; 
            Value=&quot;{ThemeResource PivotHeaderItemForegroundPointerOver}&quot; /&gt;
  &lt;/VisualState.Setters&gt;
&lt;/VisualState&gt;[/sourcecode]

<div class="x-image-left">
  <img src="https://msdnshared.blob.core.windows.net/media/2017/11/image02.png" />
  <div class="x-image-left-footer"><strong class="x-emphasis-bold">Image 2</strong> Final result.</div>
</div>

<div class="x-text-justified">With these changes the goal of applying <em class="x-emphasis-cursive">Fluent Design</em> to the app is completed. Remember to review the complete project source code on <a href="https://github.com/JuanMejiaVelez/BlogSampleCode/tree/master/UWPRibbonFluent" target="_blank" class="x-link">GitHub</a> as some small details were not mentioned in this post. And in case things don’t work as expected let me know in the comments.</div>
]]></content:encoded>
    </item>
    <item>
      <title>Office Ribbon: Styling the Pivot Control</title>
      <link>https://docs.microsoft.com/archive/blogs/juanmejia/office-ribbon-styling-the-pivot-control</link>
      <pubDate>Wed, 18 Oct 2017 22:27:47 GMT</pubDate>
      <dc:creator><![CDATA[Juan Mejia Velez]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/juanmejia/?p=386</guid>
      <description><![CDATA[One thing I love about the XAML platform is the ability to modify the visual styles of any control...]]></description>
      <content:encoded><![CDATA[<div class="x-text-justified">One thing I love about the <em class="x-emphasis-cursive">XAML</em> platform is the ability to modify the visual styles of any control without access to the source code and still benefitting from the control’s behavior.</div>

<div class="x-text-justified">While starting a project I wanted to have a similar visual style as the one found in modern versions of <em class="x-emphasis-cursive">Office</em>, specially the <em class="x-emphasis-cursive">Ribbon</em> control, but then I couldn’t find a Ribbon control in the toolkit that ships with the <a href="https://developer.microsoft.com/en-us/windows/downloads" target="_blank" class="x-link">Windows SDK</a>, and while the Ribbon control behaves very similar to a <em class="x-emphasis-cursive">Tabs</em> control there wasn’t one either for <em class="x-emphasis-cursive">UWP</em> apps. After searching for a while I found that in UWP it is the <em class="x-emphasis-cursive">Pivot</em> control the one that offers a generalized functionality like Tabs or Ribbon.</div>

<!--more-->

<div class="x-text-justified">The Pivot control offers a series of sections identified with a header and as the user selects one of those headers the content of the section is presented. The way the Pivot control made its way into <em class="x-emphasis-cursive">Windows Phone</em> and after that to Windows 8.1 and 10 was to change <em class="x-emphasis-cursive">Page</em> views. For that reason, it didn’t occur to me that it could be used as a Ribbon.</div>

<div class="x-text-justified">Now, the task is to change the styles and visual resources of the Pivot control to match as much as possible the experience of the Ribbon control found in Office.</div>

<div class="x-image-right"><img src="https://msdnshared.blob.core.windows.net/media/2017/10/image01.png" /><div class="x-image-right-footer"><strong class="x-emphasis-bold">Image 1</strong> Ribbon control used on Word Mobile.</div></div>

<div class="x-text-justified x-note"><strong>disclaimer:</strong> to implement this post I didn’t have access to any source code of the Pivot control nor the Word Mobile application. This is achieved simply by observing the behavior, taking screenshots and measuring the sizes of the different elements in the application GUI.</div>

<div class="x-text-justified">For this post, <a href="https://www.visualstudio.com/" class="x-link">Visual Studio 2017</a> (with the latest updates applied) and <strong class="x-emphasis-bold">Windows 10 Fall Creators Update</strong> will be used with its corresponding Software Development Kit.</div>

<div class="x-title-level1">Fail Fast</div>

<div class="x-text-justified">The starting point for any change to the style of a control is usually looking at the controls <em class="x-emphasis-cursive">Style</em> property where we can easily right-click the control in the Designer area or through the <em class="x-emphasis-cursive">Document Outline</em> in Visual Studio. But after trying some changes and looking at the style contents I couldn’t figure out how to totally modify the <em class="x-emphasis-cursive">PivotHeaderItem</em> to mimic those tabs found in the Ribbon control.</div>

<div class="x-text-justified">The PivotHeaderItem is the element that renders the contents assigned to the <em class="x-emphasis-cursive">Header</em> property for each <em class="x-emphasis-cursive">PivotItem</em>. But the style that defines those elements is not exposed through any <em>“style”</em> property in the Pivot control, instead we only get a <em class="x-emphasis-cursive">HeaderTemplate</em> property which generates an empty <em class="x-emphasis-cursive">DataTemplate</em> to start from scratch. Not very helpful for what we want to do.</div>

<div class="x-text-justified">I took another approach based on something I read on MSDN on the many searches for a solution, modifying the controls <em class="x-emphasis-cursive">ThemeResources</em>.</div>

<div class="x-image-left"><img src="https://msdnshared.blob.core.windows.net/media/2017/10/image02.png" /><div class="x-image-left-footer"><strong class="x-emphasis-bold">Image 2</strong> Initial application state.</div></div>

<div class="x-title-level1">Initial Setup</div>

<div class="x-text-justified">We start by creating a <em class="x-emphasis-cursive">New Project</em> in Visual Studio using the <em class="x-emphasis-cursive">Blank App</em> template for <em class="x-emphasis-cursive">Windows Universal</em>, on this I made modifications to the <strong class="x-emphasis-bold">MainPage.xaml</strong> and its code behind to extend the contents of the window to cover the window’s <em class="x-emphasis-cursive">TitleBar</em> and mimic a similar style as with the target application.</div>

<div class="x-text-justified">Following by adding a <em class="x-emphasis-cursive">ResourceDictionary</em> (<strong class="x-emphasis-bold">AppStyles.xaml</strong>) to the project where all style definitions and modifications of existing ones will be stored and added a reference to this resource in the Page section of MainPage.xaml. A series of numerical and color and brushes definitions were added to be applied to the TitleBar look.</div>

[sourcecode language="xml" title="TitleBar elements in AppStyles.xaml" firstline="38"]&lt;!-- Numerical Values for TitleBar --&gt;
&lt;x:Double x:Key=&quot;TitleBarHeight&quot;&gt;32&lt;/x:Double&gt;
&lt;x:Double x:Key=&quot;TitleBarFontSize&quot;&gt;13&lt;/x:Double&gt;
&lt;GridLength x:Key=&quot;TitleBarLeftReservedAreaWidthGridLength&quot;&gt;320&lt;/GridLength&gt;
&lt;GridLength x:Key=&quot;TitleBarRightReservedAreaWidthGridLength&quot;&gt;138&lt;/GridLength&gt;
&lt;GridLength x:Key=&quot;TitleBarCurrentUserAreaWidthGridLength&quot;&gt;182&lt;/GridLength&gt;

&lt;!-- Colors and Brushes for TitleBar--&gt;
&lt;Color x:Key=&quot;TitleBarBackgroundColor&quot;&gt;#FF6C139C&lt;/Color&gt;
&lt;Color x:Key=&quot;TitleBarForegroundColor&quot;&gt;White&lt;/Color&gt;
&lt;SolidColorBrush x:Key=&quot;TitleBarBackgroundColorBrush&quot; 
                 Color=&quot;{StaticResource TitleBarBackgroundColor}&quot; /&gt;
&lt;SolidColorBrush x:Key=&quot;TitleBarForegroundColorBrush&quot; 
                 Color=&quot;{StaticResource TitleBarForegroundColor}&quot; /&gt;[/sourcecode]

<div class="x-text-justified">In the XAML code for <strong class="x-emphasis-bold">MainPage.xaml</strong>, there is a series of <em class="x-emphasis-cursive">Grid</em> elements to layout the different pieces that made up the TitleBar, there is a reserved area to the left where some apps have the <em class="x-emphasis-cursive">Back</em> navigation button, an area for the document title, another area where Word in this case shows the current logged in user, a panel separator for aesthetics, and the window control buttons to minimize, maximize and close the program window. After that a Pivot control with a series of PivotItem elements following the sections found in the Word application.</div>

[sourcecode language="xml" title="TitleBar and Pivot Layout in MasterPage.xaml" firstline="9"]&lt;Page.Resources&gt;
  &lt;ResourceDictionary&gt;
    &lt;ResourceDictionary.MergedDictionaries&gt;
      &lt;ResourceDictionary Source=&quot;AppStyles.xaml&quot; /&gt;
    &lt;/ResourceDictionary.MergedDictionaries&gt;
  &lt;/ResourceDictionary&gt;
&lt;/Page.Resources&gt;
&lt;Grid Background=&quot;{ThemeResource ApplicationPageBackgroundThemeBrush}&quot;&gt;
  &lt;Grid.RowDefinitions&gt;
    &lt;RowDefinition Height=&quot;Auto&quot; /&gt; &lt;!-- Title Bar --&gt;
    &lt;RowDefinition Height=&quot;Auto&quot; /&gt; &lt;!-- Ribbon --&gt;
    &lt;RowDefinition /&gt; &lt;!-- Window Content --&gt;
  &lt;/Grid.RowDefinitions&gt;
  &lt;Grid x:Name=&quot;TitleBarPanel&quot; Grid.Row=&quot;0&quot; 
        Background=&quot;{StaticResource TitleBarBackgroundColorBrush}&quot;
        Height=&quot;{StaticResource TitleBarHeight}&quot;&gt;
    &lt;Grid.ColumnDefinitions&gt;
      &lt;!-- Left Reserved Area --&gt;
      &lt;ColumnDefinition Width=&quot;{StaticResource TitleBarLeftReservedAreaWidthGridLength}&quot; /&gt;
      &lt;!-- Window Title --&gt;
      &lt;ColumnDefinition  /&gt;
      &lt;!-- Current User --&gt;
      &lt;ColumnDefinition Width=&quot;{StaticResource TitleBarCurrentUserAreaWidthGridLength}&quot; /&gt;
      &lt;!-- Right Reserved Area --&gt;
      &lt;ColumnDefinition Width=&quot;{StaticResource TitleBarRightReservedAreaWidthGridLength}&quot; /&gt;
    &lt;/Grid.ColumnDefinitions&gt;
    &lt;Grid x:Name=&quot;LeftReservedColumn&quot; /&gt;
    &lt;Grid x:Name=&quot;DocumentTitlePanel&quot; Grid.Column=&quot;1&quot; 
          VerticalAlignment=&quot;Center&quot; HorizontalAlignment=&quot;Center&quot;&gt;
      &lt;TextBlock x:Name=&quot;TitleBarText&quot; Text=&quot;Document&quot;                    
                 Foreground=&quot;{StaticResource TitleBarForegroundColorBrush}&quot; 
                 FontSize=&quot;{StaticResource TitleBarFontSize}&quot; /&gt;
    &lt;/Grid&gt;
    &lt;Grid Grid.Column=&quot;2&quot;&gt;
      &lt;StackPanel Orientation=&quot;Horizontal&quot; 
                  VerticalAlignment=&quot;Center&quot; 
                  HorizontalAlignment=&quot;Right&quot;&gt;
        &lt;TextBlock x:Name=&quot;CurrentUserNameText&quot; Text=&quot;Daniel Jackson&quot; 
                   Foreground=&quot;{StaticResource TitleBarForegroundColorBrush}&quot; 
                   VerticalAlignment=&quot;Center&quot; 
                   FontSize=&quot;{StaticResource TitleBarFontSize}&quot; 
                   Margin=&quot;15,0&quot; /&gt;
        &lt;TextBlock x:Name=&quot;TitleBarSeparator&quot; Text=&quot;│&quot; 
                   Foreground=&quot;{StaticResource TitleBarForegroundColorBrush}&quot;
                   VerticalAlignment=&quot;Center&quot; 
                   Opacity=&quot;0.5&quot; 
                   Margin=&quot;17,0&quot; /&gt;
      &lt;/StackPanel&gt;
    &lt;/Grid&gt;
    &lt;Grid x:Name=&quot;SystemWindowButtonsMask&quot; Grid.Column=&quot;3&quot;/&gt;
  &lt;/Grid&gt;
  &lt;Grid x:Name=&quot;RibbonContainer&quot; Grid.Row=&quot;1&quot; Height=&quot;73&quot;&gt;
    &lt;Pivot x:Name=&quot;AppRibbon&quot;&gt;
      &lt;PivotItem Header=&quot;File&quot;&gt;
        &lt;Grid&gt;&lt;TextBlock Text=&quot;File is selected&quot;/&gt;&lt;/Grid&gt;
      &lt;/PivotItem&gt;
      &lt;PivotItem Header=&quot;Home&quot;&gt;
        &lt;Grid&gt;&lt;TextBlock Text=&quot;Home is selected&quot;/&gt;&lt;/Grid&gt;
      &lt;/PivotItem&gt;
      &lt;PivotItem Header=&quot;Insert&quot;&gt;
        &lt;Grid&gt;&lt;TextBlock Text=&quot;Insert is selected&quot;/&gt;&lt;/Grid&gt;
      &lt;/PivotItem&gt;
      &lt;PivotItem Header=&quot;Draw&quot;&gt;
        &lt;Grid&gt;&lt;TextBlock Text=&quot;Draw is selected&quot;/&gt;&lt;/Grid&gt;
      &lt;/PivotItem&gt;
      &lt;PivotItem Header=&quot;Layout&quot;&gt;
        &lt;Grid&gt;&lt;TextBlock Text=&quot;Layout is selected&quot;/&gt;&lt;/Grid&gt;
      &lt;/PivotItem&gt;
      &lt;PivotItem Header=&quot;Review&quot;&gt;
        &lt;Grid&gt;&lt;TextBlock Text=&quot;Review is selected&quot;/&gt;&lt;/Grid&gt;
      &lt;/PivotItem&gt;
      &lt;PivotItem Header=&quot;View&quot;&gt;
        &lt;Grid&gt;&lt;TextBlock Text=&quot;View is selected&quot;/&gt;&lt;/Grid&gt;
      &lt;/PivotItem&gt;
    &lt;/Pivot&gt;
  &lt;/Grid&gt;
  &lt;Grid Grid.Row=&quot;2&quot;&gt;
    &lt;TextBlock Text=&quot;This is the app Content&quot; /&gt;
  &lt;/Grid&gt;
&lt;/Grid&gt;[/sourcecode]

<div class="x-text-justified">And the code behind added to MainPage constructor to change the color of the TitleBar, specially the reserved buttons area and some instructions to extend the window contents into the area reserved for the TitleBar.</div>

[sourcecode language="csharp" title="Code in MainPage.xaml.cs" firstline="26"]// Change the colors for the TitleBar
var titleBar = ApplicationView.GetForCurrentView().TitleBar;
if (titleBar != null)
{
  // Get the resoueces values from the current Page Resources
  var bgColor = (Color)Resources[&quot;TitleBarBackgroundColor&quot;];
  var fgColor = (Color)Resources[&quot;TitleBarForegroundColor&quot;];

  titleBar.BackgroundColor = bgColor;
  titleBar.ButtonBackgroundColor = bgColor;
  titleBar.ForegroundColor = fgColor;
  titleBar.ButtonForegroundColor = fgColor;
}

// Extend the application content to cover the TitleBar provided by Windows
var coreTitleBar = CoreApplication.GetCurrentView().TitleBar;
// Set the TitleBar height
coreTitleBar.LayoutMetricsChanged += 
  (CoreApplicationViewTitleBar sender, object args) =&gt; TitleBarPanel.Height = sender.Height;

coreTitleBar.ExtendViewIntoTitleBar = true;
// Set the area that respond to dragging operations in the window
Window.Current.SetTitleBar(TitleBarPanel);[/sourcecode]

<div class="x-title-level1">Modifying the Pivot control</div>

<div class="x-tooltip">To modify the Pivot control, we will use some of the Theme elements and Styles found in the <strong class="x-emphasis-bold">generic.xaml</strong> ResourceDictionary that all controls from the SDK use. This file is located for the developer’s convenience at the <em class="x-emphasis-cursive">\[Program Files]\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\UAP\[Windows SDK version]\Generic</em> folder. From this file, we can search for all the elements that contain <em>“Pivot”</em> on its key value. Although not all of them need to be modified and to keep things simple, I will only override the ones that required a value change.</div>

<div class="x-text-justified">We copy into our own ResourceDictionary the elements to override into a ThemeResources section and assign the new values. This will cause that the controls that have references to this resources will take our changes first, and if we didn’t modify them, they use the default values.</div>

[sourcecode language="xml" title="ThemeResources modifications in AppStyles.xaml" firstline="11"]&lt;ResourceDictionary.ThemeDictionaries&gt;
  &lt;ResourceDictionary x:Key=&quot;Default&quot;&gt;
    &lt;FontFamily x:Key=&quot;PivotHeaderItemFontFamily&quot;&gt;Segoe UI&lt;/FontFamily&gt;
    &lt;FontWeight x:Key=&quot;PivotHeaderItemThemeFontWeight&quot;&gt;Normal&lt;/FontWeight&gt;
    &lt;x:Double x:Key=&quot;PivotHeaderItemFontSize&quot;&gt;13&lt;/x:Double&gt;
    &lt;Thickness x:Key=&quot;PivotHeaderItemMargin&quot;&gt;16,0,16,3&lt;/Thickness&gt;
    &lt;Thickness x:Key=&quot;PivotItemMargin&quot;&gt;20,0&lt;/Thickness&gt;

    &lt;!-- Resources for Windows.UI.Xaml.Controls.Pivot --&gt;
    &lt;StaticResource x:Key=&quot;PivotBackground&quot; ResourceKey=&quot;PivotItemBackgroundColorBrush&quot; /&gt;
    &lt;StaticResource x:Key=&quot;PivotHeaderBackground&quot; ResourceKey=&quot;PivotHeaderBackgroundColorBrush&quot; /&gt;

    &lt;!-- Resources for Windows.UI.Xaml.Controls.Primitives.PivotHeaderItem --&gt;
    &lt;StaticResource x:Key=&quot;PivotHeaderItemBackgroundUnselectedPointerOver&quot;
                    ResourceKey=&quot;PivotItemBackgroundColorMediumLowBrush&quot; /&gt;
    &lt;StaticResource x:Key=&quot;PivotHeaderItemBackgroundUnselectedPressed&quot; 
                    ResourceKey=&quot;PivotItemBackgroundColorMediumLowBrush&quot; /&gt;
    &lt;StaticResource x:Key=&quot;PivotHeaderItemBackgroundSelected&quot;
                    ResourceKey=&quot;PivotItemBackgroundColorBrush&quot; /&gt;
    &lt;StaticResource x:Key=&quot;PivotHeaderItemBackgroundSelectedPointerOver&quot;
                    ResourceKey=&quot;PivotItemBackgroundColorBrush&quot; /&gt;
    &lt;StaticResource x:Key=&quot;PivotHeaderItemBackgroundSelectedPressed&quot;
                    ResourceKey=&quot;PivotItemBackgroundColorBrush&quot; /&gt;
    &lt;StaticResource x:Key=&quot;PivotHeaderItemForegroundUnselected&quot;
                    ResourceKey=&quot;PivotHeaderForegroundColorBrush&quot; /&gt;
    &lt;StaticResource x:Key=&quot;PivotHeaderItemForegroundUnselectedPointerOver&quot;
                    ResourceKey=&quot;PivotHeaderForegroundColorBrush&quot; /&gt;
    &lt;StaticResource x:Key=&quot;PivotHeaderItemForegroundUnselectedPressed&quot;
                    ResourceKey=&quot;PivotHeaderForegroundColorBrush&quot; /&gt;
    &lt;StaticResource x:Key=&quot;PivotHeaderItemForegroundSelected&quot;
                    ResourceKey=&quot;PivotHeaderBackgroundColorBrush&quot; /&gt;
    &lt;StaticResource x:Key=&quot;PivotHeaderItemForegroundSelectedPointerOver&quot;
                    ResourceKey=&quot;PivotHeaderBackgroundColorBrush&quot; /&gt;
    &lt;StaticResource x:Key=&quot;PivotHeaderItemForegroundSelectedPressed&quot;
                    ResourceKey=&quot;PivotHeaderBackgroundColorBrush&quot; /&gt;
  &lt;/ResourceDictionary&gt;
&lt;/ResourceDictionary.ThemeDictionaries&gt;[/sourcecode]

<div class="x-text-justified">As we change some of the values for the Theme resources we might notice that certain changes get reflected immediately on the Designer in Visual Studio, but other changes will require to <em class="x-emphasis-cursive">Build</em> the project, so changes get compiled and the Designer refreshes its cache values for those resources.</div>

<div class="x-image-right"><img src="https://msdnshared.blob.core.windows.net/media/2017/10/image03.png" /><div class="x-image-left-footer"><strong class="x-emphasis-bold">Image 3</strong> Impact of changing ThemeResources.</div></div>

<div class="x-text-justified">After all the possible modifications to themes, there is still some changes to get closer to have a Pivot that resembles the Ribbon in Word, for that we need to modify some values on elements of the Pivot, PivotItem and PivotHeaderItem styles.</div>

<div class="x-text-justified">To avoid getting lost in the contents of the styles and not making this post even longer, I will only point to the particular changes to the styles but you can have access to the complete sample code for this post at <a href="https://github.com/JuanMejiaVelez/BlogSampleCode" target="_blank" class="x-link">GitHub</a>.</div>

<div class="x-text-justified">The ThemeResources in the previous code excerpt made some references to a series of Brushes that were not previously presented. Those are the colors for the Pivot control copied from the values used for the TitleBar but I wanted to have separate identifiers for them in case we wanted to quickly made changes that affect only one control.</div> 

[sourcecode language="xml" title="Pivot Colors and Brushes in AppStyles.xaml" firstline="51"]  &lt;!-- Numeric Values for Pivot --&gt;
&lt;x:Double x:Key=&quot;SideHeaderWidth&quot;&gt;20&lt;/x:Double&gt;
&lt;x:Double x:Key=&quot;SideHeaderHeight&quot;&gt;32&lt;/x:Double&gt;

&lt;!-- Colors and Brushes for Pivot --&gt;
&lt;Color x:Key=&quot;PivotHeaderBackgroundColor&quot;&gt;#FF6C139C&lt;/Color&gt;
&lt;Color x:Key=&quot;PivotHeaderForegroundColor&quot;&gt;White&lt;/Color&gt;
&lt;Color x:Key=&quot;PivotItemBackgroundColor&quot;&gt;#FFF3F3F3&lt;/Color&gt;
&lt;SolidColorBrush x:Key=&quot;PivotHeaderBackgroundColorBrush&quot;
                 Color=&quot;{StaticResource PivotHeaderBackgroundColor}&quot; /&gt;
&lt;SolidColorBrush x:Key=&quot;PivotHeaderForegroundColorBrush&quot;
                 Color=&quot;{StaticResource PivotHeaderForegroundColor}&quot; /&gt;
&lt;SolidColorBrush x:Key=&quot;PivotItemBackgroundColorBrush&quot;
                 Color=&quot;{StaticResource PivotItemBackgroundColor}&quot; /&gt;
&lt;SolidColorBrush x:Key=&quot;PivotItemBackgroundColorMediumLowBrush&quot;
                 Color=&quot;{StaticResource PivotItemBackgroundColor}&quot;
                 Opacity=&quot;0.4&quot; /&gt;[/sourcecode]

<div class="x-text-justified">The style for the Pivot control, look in the source code for <em class="x-emphasis-cursive">“style for Windows.UI.Xaml.Controls.Pivot”</em>, contains five minimal changes, 3 of them are numeric values and the other 2 add properties to a pair of <em class="x-emphasis-cursive">ControlPresenter</em>s. The numeric values affect the following elements, the Grid <em class="x-emphasis-cursive">“PivotLayoutElement”</em> which defines two rows had its first row's <em class="x-emphasis-cursive">Height</em> value changed from <em class="x-emphasis-cursive">Auto</em> to <em class="x-emphasis-cursive">32</em>. This is the height of the tabs area for the Ribbon. The other two numerical changes were in the Height property of the Buttons <em class="x-emphasis-cursive">“PreviousButton”</em> and <em class="x-emphasis-cursive">“NextButton”</em> from <em class="x-emphasis-cursive">36</em> to <em class="x-emphasis-cursive">32</em> as they need to fit in the row defined for the Ribbon’s tabs. The remaining two changes on the ControlPresenters are highlighted in the below code fragments.</div>

[sourcecode language="xml" title="Changes to LeftHeaderPresenter in Pivot Style" firstline="321" highlight="326,327,328"]&lt;ContentPresenter x:Name=&quot;LeftHeaderPresenter&quot;
                  Content=&quot;{TemplateBinding LeftHeader}&quot;
                  ContentTemplate=&quot;{TemplateBinding LeftHeaderTemplate}&quot;
                  HorizontalAlignment=&quot;Stretch&quot;
                  VerticalAlignment=&quot;Stretch&quot;
                  Height=&quot;{StaticResource SideHeaderHeight}&quot;
                  Background=&quot;{StaticResource PivotHeaderBackgroundColorBrush}&quot;
                  Width=&quot;{StaticResource SideHeaderWidth}&quot;/&gt;[/sourcecode]

[sourcecode language="xml" title="Changes to RightHeaderPresenter in Pivot Style" firstline="378" highlight="384,385,386"]&lt;ContentPresenter x:Name=&quot;RightHeaderPresenter&quot;
                  Grid.Column=&quot;2&quot;
                  Content=&quot;{TemplateBinding RightHeader}&quot;
                  ContentTemplate=&quot;{TemplateBinding RightHeaderTemplate}&quot;
                  HorizontalAlignment=&quot;Stretch&quot;
                  VerticalAlignment=&quot;Stretch&quot;
                  Height=&quot;{StaticResource SideHeaderHeight}&quot;
                  Background=&quot;{StaticResource PivotHeaderBackgroundColorBrush}&quot;
                  Width=&quot;{StaticResource SideHeaderWidth}&quot;/&gt;[/sourcecode]

<div class="x-text-justified">For the PivotItem style, search for <em class="x-emphasis-cursive">“style for Windows.UI.Xaml.Controls.PivotItem”</em> in the source code of <strong class="x-emphasis-bold">AppStyle.xaml</strong> there are two changes. The value for the <em class="x-emphasis-cursive">Setter</em> property <em class="x-emphasis-cursive">VerticalContentAlignment</em> changed from <em class="x-emphasis-cursive">Stretch</em> to <em class="x-emphasis-cursive">Center</em>. And the Grid serving as container for the <em class="x-emphasis-cursive">ControlTemplate</em> got two additional properties, <em class="x-emphasis-cursive">BorderBrush</em> and <em class="x-emphasis-cursive">BorderThickness</em>.</div>

[sourcecode language="xml" title="ControlTemplate container change in AppStyles.xaml" firstline="416" highlight="419,420"]&lt;Grid Background=&quot;{TemplateBinding Background}&quot; 
        HorizontalAlignment=&quot;{TemplateBinding HorizontalAlignment}&quot; 
        VerticalAlignment=&quot;{TemplateBinding VerticalAlignment}&quot;
        BorderBrush=&quot;LightGray&quot;
        BorderThickness=&quot;0,0,0,1&quot;&gt;[/sourcecode]

<div class="x-text-justified">The last set of changes are in the PivotHeaderItem style, search for <em class="x-emphasis-cursive">“style for Windows.UI.Xaml.Controls.Primitives.PivotHeaderItem”</em> in the source code. Changes to this style are two, the first is to change the value of the <em class="x-emphasis-cursive">Height</em> property on the style <em class="x-emphasis-cursive">Setter</em> from <em class="x-emphasis-cursive">48</em> to <em class="x-emphasis-cursive">32</em> as seen in previous changes this represents the height of the tabs row in the Ribbon. The other change is in the <em class="x-emphasis-cursive">ControlTemplate</em> container adding to the <em class="x-emphasis-cursive">Grid</em> a <em class="x-emphasis-cursive">CornerRadius</em> property with value <em class="x-emphasis-cursive">"2,2,0,0"</em> to set the rounded corners of the tabs. As we can see in image 3, that’s the most noticeable missing change to achieve our goal.</div>

[sourcecode language="xml" title="Border definition for PivotHeaderItem in AppStyle.xaml" firstline="456" highlight="459"]&lt;Grid x:Name=&quot;Grid&quot; 
      Background=&quot;{TemplateBinding Background}&quot;
      Padding=&quot;{TemplateBinding Padding}&quot; 
      CornerRadius=&quot;2,2,0,0&quot;&gt;[/sourcecode]

<div class="x-image-right"><img src="https://msdnshared.blob.core.windows.net/media/2017/10/image04.png" /><div class="x-image-left-footer"><strong class="x-emphasis-bold">Image 4</strong> Final Ribbon effect.</div></div>

<div class="x-text-justified">After all these changes are in place, we can build and run the solution to observe the effect. Notice that while our changes makes the experience quite similar, we didn’t copy the entire behavior of the Ribbon control. If we look closer into the Ribbon in Word we will see that as we move the mouse over the unselected tabs, their background change into a color that is not quite solid, as in our code, it feels more like a gradient brush. Also the tabs at each side of the one being hovered get a small glowing background effect creating a more vivid illusion of light, it is a nice touch, but was not part of what I planned to do. I kept thinking on how that could be implemented, might it be possible that such effect is part of the new <a href="https://docs.microsoft.com/en-us/windows/uwp/fluent-design-system/" target="_blank" class="x-link">Fluent Design</a>? Certainly, I will revisit this in a future post.</div>

<div class="x-text-justified">You can find the complete source code for this article on <a href="https://github.com/JuanMejiaVelez/BlogSampleCode/tree/master/UWPRibbonStyle" target="_blank" class="x-link">GitHub</a> and use it as a starting point for your project.</div>
]]></content:encoded>
    </item>
  </channel>
</rss>