I set the icons in my SecondaryCommand of CommandBar but aren't shown. Why?
<CommandBar RelativePanel.AlignRightWithPanel="True" RelativePanel.AlignVerticalCenterWithPanel="True" Margin="0">
<CommandBar.SecondaryCommands>
<AppBarButton Name="shareButton" Label="Condividi" x:Uid="condividi" Click="shareButton_Click" Icon="ReShare" />
<AppBarButton Name="contactButton" Icon="Contact" x:Uid="contatti" Label="Contatti" Click="contactButton_Click" />
</CommandBar.SecondaryCommands>
</CommandBar>
Well its pretty easier than this, use the reference microsoft.midiGmDls in your proyect and it's done.
Damir's answer somehow put me on the right track and after spending a stupid amount of time on this, I eventually found out a solution that's simple.
Note that it may not suit everyone as the buttons don't get highlighted when hovering over with your mouse but it's the closest and easiest way I've figured out on how to do it on a UWP solution
First define a
ControlTemplate
in yourStyles.xaml
or yourPage.Resources
as such:Then simply define the
Template
yourSecondaryCommands
:It's a simple as that! What I don't get is that after following Damir's suggestion, and examining the XAML style that was generated for the button, I ended up removing all the visual states and I noticed that both my icon and text were displayed!! Why?? I don't understand why would
Microsoft
want to hide the icon in theSecondaryCommands
and I'll be honest, I didn't spot the specific code that actually did it. Once I removed all the VisualStates, I noticed I was left with a template and then it was just a case of adding a grid and playing around withVerticalAlignment
,HorizontalAlignment
and 'Margin'.Hope this helps!
They are not shown because of the default
AppBarButton
template. You will need to modify it.Just follow these steps:
AppBarButton
in theCommandBar.PrimaryCommands
collection.MyAppBarButtonStyle
Set this style to your secondary buttons:
Modify the style to your liking.
By default the following elemnt is used in the overflow menu:
You might want to replace it with something like that:
You will also need to modify the overflow visual state to display your new template:
And increase the button width:
Of course, you'll want to further modify the template to your liking, but this should at least get you going.
Here's a much simpler, less elegant, way to do it. It works because most UWP icons are glyphs of the Segoe MDL2 Assets Font included in Windows.
<CommandBar.SecondaryCommands> <AppBarButton FontFamily="Segoe MDL2 Assets" Label=" Help"/> <AppBarButton FontFamily="Segoe MDL2 Assets" Label=" Update database"/> </CommandBar.SecondaryCommands>
And this is what you'll get.
I use this technique in an app that's localised to Russian and Chinese with no problems.