AppBarButton.Icon doesn't change on runtime

a 夏天 提交于 2019-12-23 18:34:03

问题


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.


回答1:


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;



回答2:


Force InvalidateArrange and it works

WeekButton.Icon = new FontIcon() { Glyph = "\uE29B", FontFamily = new FontFamily("Segoe UI Symbol")};
WeekButton.InvalidateArrange();



回答3:


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)



来源:https://stackoverflow.com/questions/28069541/appbarbutton-icon-doesnt-change-on-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!