在wpf中,我加了个image控件 <Image Margin="-13.5,-5,-13.5,0" Name="image1" Source="D:\wpf\project\xiun\xiun\bin\Debug\image\bg.bmp" Grid.RowSpan="2" />这样绝对路径可以显示
单是改成相对路径就不行了
<Image Margin="-13.5,-5,-13.5,0" Name="image1" Source="image\bg.bmp" Grid.RowSpan="2" />
我想用相对路径,该怎么办??谢谢

解决方案 »

  1.   

    <Window x:Class="WpfApplication1.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="300" Width="300">
        <Grid>
            <Image Margin="10,10,68,102" Name="image1" Stretch="Fill" Source="image/1.jpg" />
        </Grid>
    </Window>
      

  2.   

    <Window x:Class="WpfApplication1.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="300" Width="300">
        <Grid>
            <Image Margin="10,10,68,102" Name="image1" Stretch="Fill" Source="image/1.jpg" />
        </Grid>
    </Window>注意红色部分你需要在Project的根目录下建一个Image目录,1.jpg在此目录中。路径中应该为“/”斜线我就是在cs下做的。
      

  3.   

    D:\wpf\project\xiun\xiun\bin\Debug
    你不会是在Debug下建的image目录,但编译程序却用release吧
      

  4.   

    D:\wpf\project\xiun\xiun\bin\Debug\image\bg.bmp"
    你把image文件夹copy到D:\wpf\project\xiun\xiun目录下
    然后把<Image Margin="-13.5,-5,-13.5,0" Name="image1" Source="image\bg.bmp" Grid.RowSpan="2" /> 
    改为: <Image Margin="-13.5,-5,-13.5,0" Name="image1" Source="image/bg.bmp" Grid.RowSpan="2" /> 
     你再试试看,应该没有问题的。
      

  5.   

    Source属性类型是ImageSource 
    <Image Source="images/a.png" Width="20" Height="20" />