3

I have a problem updating AppBarButton Icon on runtime depending on some conditions.

<AppBarButton x:Name="WeekButton" Click="OnClick" Label="SomeText"

</AppBarButton>

I'm trying to update Icon property in some code behind with this code

WeekButton.Icon = new FontIcon() { Glyph = Runtime_Value_Here};

But nothing happens. The button doesn't change. But in any random time when the code works, It MAY change the button. I always see, that the Icon is new in code, but not on screen. None of the UpdateLayout helps. Would appreciate any help. Thanks

UPDATE: It seems to not working with FontIcon, as with BitmapIcon changing everything works fine.

Viachslau
  • 361
  • 2
  • 11

3 Answers3

2

Force InvalidateArrange and it works

WeekButton.Icon = new FontIcon() { Glyph = "\uE29B", FontFamily = new FontFamily("Segoe UI Symbol")};
WeekButton.InvalidateArrange();
Igor Ralic
  • 14,975
  • 4
  • 43
  • 51
2

I believed you already found the solution with bitmap icon. But some people who reached this page and want to know the solution like me,

Here is using bitmap icon and changing app-bar button icon dynamically.

BitmapIcon _bitmapIcon = new BitmapIcon();
_bitmapIcon.UriSource = new Uri("ms-appx:///Assets/yourBitmapIcon.png");
WeekButton.Icon = _bitmapIcon;
Zin Min
  • 3,898
  • 1
  • 20
  • 24
0

Try using the IconUri in order to give the value.

WeekButton.IconUri = new Uri("/Images/pause.png", UriKind.Relative);

Reference: Disable/Enable applicationbar Button in runtime with event textchanged (Windows Phone)

Community
  • 1
  • 1
Kulasangar
  • 9,046
  • 5
  • 51
  • 82
  • Thanks, but in fact there isn't any, as this is universal winrt app, not wp Silverlight. Another problem is that I use runtime values for icons, so the uri won't work too. – Viachslau Jan 21 '15 at 19:20