0
votes

I want to add remote Image into app bar button. My image is this url http://2.bp.blogspot.com/-yEbb9_qp-jg/U8-KGeZAy3I/AAAAAAAAB0U/m91Bv1jPAQI/s1600/india+win+at+lords.jpg and I want to bind it to appbarbutton from the backend. my backend code is propic.UriSource = new Uri("http://2.bp.blogspot.com/-yEbb9_qp-jg/U8-KGeZAy3I/AAAAAAAAB0U/m91Bv1jPAQI/s1600/india+win+at+lords.jpg"); But my backend code is not working...someone please tell me how to do it

And below is my Xaml code

            <AppBarButton Label="Ride Now">
                <AppBarButton.Icon>

                    <BitmapIcon x:Name="propic" Height="100" Width="100"/>
                </AppBarButton.Icon>
            </AppBarButton>
            <CommandBar.SecondaryCommands>
                <AppBarButton Label="Ride Now">
                <AppBarButton.Icon>

                    <BitmapIcon x:Name="propic12" Height="100" Width="100"/>
                </AppBarButton.Icon>   
                </AppBarButton>
                <AppBarButton Label="x" Icon="Admin" />
                </CommandBar.SecondaryCommands>
        </CommandBar>
    </Page.BottomAppBar>
1

1 Answers

0
votes

You can't give an absolute Uri to AppBar Images , AppBarButtons just don't work that way.

What might work is you can download your image , save it to local storage and read as image from there.Don't forget that your images need to follow sizing formats.

You can get some more additional info here

https://msdn.microsoft.com/en-us/library/windows/apps/ff431806%28v=vs.105%29.aspx

Here's the code that will help you.

using (var htc = new HttpClient())
{
    var file = await htc.GetStreamAsync("Your image url");
    if (!isoStore.FileExists("shared/shellcontent/appbarimage.png"))
    {
        using (IsolatedStorageFileStream fileStream = isoStore.OpenFile("shared/shellcontent/appbarimage.png", FileMode.Create))
        {
            await file.CopyToAsync(fileStream);
        }
    }
}

propic.UriSource = new Uri("isostore:/Shared/ShellContent/appbarimage.png",UriKind.Relative);