WP7 Dynamic icons in ApplicationBar

久未见 提交于 2019-12-10 11:43:28

问题


Dynamic icons in ApplicationBar

It's possible to have dynamic icons in ApplicationBar with dynamic images loaded from url? I tried this:

xaml:

<phone:PhoneApplicationPage.ApplicationBar>
    <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
        <shell:ApplicationBarIconButton IconUri="" Text="Button 1"/>
        <shell:ApplicationBarIconButton IconUri="" Text="Button 2"/>
        <shell:ApplicationBar.MenuItems>
            <shell:ApplicationBarMenuItem Text="MenuItem 1"/>
            <shell:ApplicationBarMenuItem Text="MenuItem 2"/>
        </shell:ApplicationBar.MenuItems>
    </shell:ApplicationBar>

cs:

var myIcon = ApplicationBar.Buttons[1] as ApplicationBarIconButton;
myIcon.IconUri = new Uri(iconImageUrl, UriKind.Absolute);

I'm getting error: Path cannot be absolute.


回答1:


Chage the second parametr to UriKind.Relative if the uri is relative - looks like this one:

"/Images/icon.png" 



回答2:


I think the best idea is to save your image in isolated storage and call it with UriKind.Relative.




回答3:


Full setting appbar IconUri, see:



来源:https://stackoverflow.com/questions/4592236/wp7-dynamic-icons-in-applicationbar

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