【问题标题】:Windows Phone 8.1 : Add remote Image to BottomAppBar or AppBarButtonWindows Phone 8.1:将远程图像添加到 BottomAppBar 或 AppBarButton
【发布时间】:2015-06-06 12:20:42
【问题描述】:

我想将远程图像添加到应用栏按钮。 我的图片是这个网址http://2.bp.blogspot.com/-yEbb9_qp-jg/U8-KGeZAy3I/AAAAAAAAB0U/m91Bv1jPAQI/s1600/india+win+at+lords.jpg 我想将它从后端绑定到 appbarbutton 。我的后端代码是propic.UriSource = new Uri("http://2.bp.blogspot.com/-yEbb9_qp-jg/U8-KGeZAy3I/AAAAAAAAB0U/m91Bv1jPAQI/s1600/india+win+at+lords.jpg"); 但是我的后端代码不起作用...请告诉我该怎么做

下面是我的 Xaml 代码

            <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>

【问题讨论】:

    标签: c# xaml windows-phone-8 windows-phone-8.1 windows-phone-7.1


    【解决方案1】:

    你不能给 AppBar Images 一个绝对的 Uri,AppBarButtons 不能那样工作。

    您可以下载图像,将其保存到本地存储并从那里读取为图像。不要忘记您的图像需要遵循尺寸格式。

    您可以在此处获取更多其他信息

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

    这里的代码可以帮助你。

    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);
    

    【讨论】:

    • 它说isoStore在当前上下文中不存在并且IsoloatedStorageFileStream在当前上下文中不存在...实际上windows.storage.IsolatedStorage仅适用于windowsphone8.1
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多