question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot set AppBarButton Icon from Style

See original GitHub issue

Hi @Kinnara,

thank you for all your work on this great library!

I tried to define a Style for an AppBarButton that speciffes the AppBarButton.Icon property. Apparently, the Style only works on a single instance of the button. If multiple buttons apply the same style, then only the last button will display the icon.

The Icon property is of type IconElement : FrameworkElement. AFAIK, an element can only be used once in the visual tree. I haven’t been able to find a workaround for this current limitation.

Usually, control properties are either Freezable or a pair of { Content, ContentTemplate }, to allow templating.

Maybe the new IconSource provides an elegant solution to this problem?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
Kinnaracommented, Dec 6, 2020

This is actually possible in WPF, thanks to the x:Shared attribute:

<ui:SymbolIcon x:Key="SaveIcon" Symbol="Save" x:Shared="False" />

<Style x:Key="SaveButtonStyle" TargetType="ui:AppBarButton">
    <Setter Property="Icon" Value="{StaticResource SaveIcon}" />
    <Setter Property="Label" Value="Save" />
</Style>
<ui:CommandBar>
    <ui:AppBarButton Style="{StaticResource SaveButtonStyle}" />
    <ui:AppBarButton Style="{StaticResource SaveButtonStyle}" />
    <ui:AppBarButton Style="{StaticResource SaveButtonStyle}" />
</ui:CommandBar>
1reaction
wmruttencommented, Dec 18, 2020

Hi @Kinnara , thank you for your feedback.

Indeed, the issue is related to resource sharing. I am aware of the x:Shared attribute, it fixes the problem for global resources declared in XAML.

In this case, I was trying to provide the icon resource in a Style through a (custom) markup extension that returns a (custom) FontIcon, programmatically. The markup extension would need to return a separate FontIcon instance for each target control that the style is applied to, similar to x:Shared behavior. Maybe this is possible by hooking the target control from the markup extension, but I didn’t explore any further.

Nonetheless, I understand the motivations for this library to stay close to the original UWP interface and I’m perfectly happy w/o support for AppBarButton styling.

Thanks for all you hard work, guys. This library provides great UI improvements that are happily received by our app users. Quite amazing to see WinUI design running on an old Windows 7 (!) machine.

Kudos and keep it up!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to change AppBarButton circle and icon color ...
I want to customize the circle and icon color of AppBarButton so far I tried following style but it does not work. In...
Read more >
Style not applied inside MenuFlyoutItem.Icon · Issue #1217
Describe the bug I'd like to apply a style for all SymbolIcon elements of my app, but it seems that this is not...
Read more >
XAML AppBarButton Bottom Border disapears by changing ...
You know why the border bottom disapears by changing the height under 40 ? Where in the Style can i change the values...
Read more >
Making app bar button larger - Icon doesn't show when in ...
Hi Kmm,. Group the icon and the app bar together then go to “Edit Styles” then fix it to the top.
Read more >
Using vector data for AppBar icons in XAML
I set my Button to use the base style, then set my label (via AutomationProperties.Name) and the Content is the exported vector data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found