c# Windows手机页面背景没有设置

本文关键字:设置 背景 Windows 手机 | 更新日期: 2023-09-27 17:50:55

我想设置一个页面背景,我从web下载的图像,它只在设计器视图中工作。但是当我在模拟器或设备上启动应用程序时,它只是不起作用(它不会下载和设置)。Mainfest设置为需要互联网连接。我已经试着找到解决办法了,但是没有成功。

<Page
    x:Class="App1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App1"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    <Page.Background>
        <ImageBrush Stretch="UniformToFill">
            <ImageBrush.ImageSource>
                <BitmapImage UriSource="http://i.imgur.com/XAAcx5d.jpg"/>
            </ImageBrush.ImageSource>
        </ImageBrush>
    </Page.Background>
</Page>

c# Windows手机页面背景没有设置

似乎你的图像有热链接保护。

您可以尝试手动加载图像:1或2。或者您可以尝试将控件<Image ...>添加到XAML中,然后订阅Image类的事件ImageFailed,看看发生了什么。

像这样修改你的代码

<Page
    x:Class="App1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App1"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    <Page.Background>           
     <ImageBrush ImageSource="http://i.imgur.com/XAAcx5d.jpg" Stretch="UniformToFill"/>              
    </Page.Background>
</Page>