1

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.

Janci
  • 863
  • 1
  • 9
  • 24

3 Answers3

3

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

"/Images/icon.png" 
Lukasz Madon
  • 14,664
  • 14
  • 64
  • 108
  • From a webpage? you can't. Use http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest%28v=VS.95%29.aspx – Lukasz Madon Jan 04 '11 at 12:29
  • Please explain more, I know how to work with dynamic Bitmaps using HttpWebRequest, but I don't know how to assign dynamic Bitmap to ApplicationBar icon. – Janci Jan 04 '11 at 16:07
1

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

Igor
  • 11
  • 1
  • @Janci I suppose, you can download to Isolated Storage and use it as relative. When required, download the image in background. Even this way can serve dynamism. Are you looking for something different? – Prakash Jan 04 '12 at 19:57
0

Full setting appbar IconUri, see:

j0k
  • 22,600
  • 28
  • 79
  • 90
Newred
  • 699
  • 8
  • 8