0

I have this code:

<Window x:Class="wpf_2.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525" WindowStyle="None" WindowState="Maximized">
<Grid>
    <Button Content="Button" HorizontalAlignment="Left" Margin="287,147,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click_2"/>
    <Image Source="bg.png" Stretch="UniformToFill"></Image>
</Grid>

But when I run the project only the button was shown not the background image.

Alina Cam
  • 1
  • 2
  • 1
    Where is placed "bg.png"? It is a resource? A file on disk? Something else? – Alberto Sep 07 '13 at 13:40
  • I placed it on C:\Users\ASUS\Documents\Visual Studio 2012\Projects\wpf_2\wpf_2 – Alina Cam Sep 07 '13 at 13:42
  • You'll have to add the image file to your Visual Studio project (perhaps in a subfolder) and then set its Build Action to `Resource`, as shown [here](http://stackoverflow.com/a/12693661/1136211) for example. – Clemens Sep 07 '13 at 14:41
  • I've created a folder named "Images" in projects folder where the bg.png was located but I cant find the Images folder in the VS solution explorer. – Alina Cam Sep 07 '13 at 15:09
  • The folder is not strictly necessary. However, if you want to have one, you'll have to create it in Visual Studio by right-clicking on the project, then select `Add` > `New Folder`. – Clemens Sep 07 '13 at 15:31
  • So why the bg.png is still not showing in my wpf form? I drag the image from destop to solution explorer I put it under Properties folder and set the Build Action to Resource but still it didnt work. – Alina Cam Sep 07 '13 at 15:46
  • Set `Copy to Output Directory` to `Copy Always` as well. – jamesSampica Sep 07 '13 at 18:37
  • Did you then change the XAML to `Source="Properties/bg.png"`? – Clemens Sep 07 '13 at 18:37
  • @Shoe Not necessary for resource files, as they aren't copied to the output directory – Clemens Sep 07 '13 at 18:38
  • @AlinaCam Leave `Copy to Output Directory` set to `Do not copy`. – Clemens Sep 07 '13 at 18:44

0 Answers0