WPF-13:资源文件需要手动引用问题

最近碰到一个问题。
两个自定义控件,其中用到图片,即<Image Source="图片路径" />。
控件1:
<UserControl x:Class="TestImageSource.UserControl1"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <Image Source="TestImageSource;component/Images/laugh.gif" />
    </Grid>
</UserControl>

控件2:
<UserControl x:Class="TestImageSource.UserControl2"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <Image Source="/TestImageSource;component/Images/laugh.gif" />
    </Grid>
</UserControl>

调用该控件:
<Window x:Class="TestImageSource.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="520" Width="1022" xmlns:my="clr-namespace:TestImageSource">
    <Grid>
        <my:UserControl1 HorizontalAlignment="Left" Margin="21,12,0,0" x:Name="userControl11" VerticalAlignment="Top" Height="267" Width="423" />
        <my:UserControl2 HorizontalAlignment="Left" Margin="540,58,0,0" x:Name="userControl21" VerticalAlignment="Top" Height="320" Width="411" />
    </Grid>
</Window>

区别在于第一个控件的Source="TestImageSource;component/Images/laugh.gif" 是手动填写。第二个则是,属性-source-选择图片。
结果造成,作为控件使用时,控件1无法显示图片,控件2正常显示图片。如下:

不知是本地环境有问题还是原本如此,所以同样使用的需要注意了,还是手动选择图片吧。

代码下载:http://download.csdn.net/detail/yysyangyangyangshan/5234502

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值