AppBarButton.Icon 在运行时不会改变 [英] AppBarButton.Icon doesn't change on runtime

查看:20
本文介绍了AppBarButton.Icon 在运行时不会改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据某些条件,我在运行时更新 AppBarButton 图标时遇到问题.

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

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

</AppBarButton>

我正在尝试使用此代码更新某些代码中的 Icon 属性

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

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

但是什么也没发生.按钮没有变化.但是在代码工作的任何随机时间,它可能会更改按钮.我总是看到,图标在代码中是新的,但不是在屏幕上.UpdateLayout 没有任何帮助.将不胜感激任何帮助.谢谢

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

更新:它似乎不适用于 FontIcon,因为 BitmapIcon 改变一切正常.

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

推荐答案

我相信您已经找到了带有位图图标的解决方案.但是有些人像我一样到达了这个页面并想知道解决方案,

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;

这篇关于AppBarButton.Icon 在运行时不会改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆