【问题标题】:Define background image inside UserControl在 UserControl 中定义背景图像
【发布时间】:2017-04-04 19:12:49
【问题描述】:

我是 Windows phone 开发的新手,在 UserControl 中设置背景图像时遇到了困难。我希望将其作为静态资源,该图像仅适用于特定的 xaml 文件。已经存储了 在我项目的 Assets 文件夹中。使用下面的代码,我仍然无法在预览窗口中看到我的图像

这是我的 xaml 文件:

<UserControl
x:Class="OrangePulse.LoginControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:OrangePulse"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="800"
d:DesignWidth="500">

<UserControl.Resources>

    <BitmapImage x:Key="splashScreen" UriSource="/Assets/loginBgd.png"/>
</UserControl.Resources>

【问题讨论】:

    标签: c# xaml user-controls windows-phone-8.1 wpf-controls


    【解决方案1】:

    在您的代码中,您只在资源集合中添加了图像。

    <UserControl.Resources>
        <BitmapImage x:Key="splashScreen" UriSource="/Assets/loginBgd.png"/>
    </UserControl.Resources>
    

    您必须将此资源绑定到任何控件才能显示图像...就像添加吹线一样它将显示图像..

     <UserControl.Resources>
        <BitmapImage x:Key="splashScreen" UriSource="/Assets/loginBgd.png"/>
       </UserControl.Resources>
    **<Image  Source="{StaticResource splashScreen}"/>**
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-04
      • 2013-10-13
      • 2021-06-03
      • 2011-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多