1

I'm having some difficulty getting an image to display in WPF, Visual Studio Community Edition 2015.

The first issue involves a lack of dialog in the "Source" property for the image. WPF Tutorials of VS show a way to browse for the file under the source property.This does not appear to be an option under VS 2015 Community edition. Is there any way to enable this feature? Or is it not enabled in the "Community" edition?

The second issue is, the image is not visible at run time, but visible in the designer. Previous posts suggest to enable the "Build Action" for this image to "Resource". There seems to be number of files to set the Build Action on: If I set the MainWindow.xaml file to BuildAction->Resource I get the following error:

Error CS0103 The name 'InitializeComponent' does not exist in the current context

.... If I try to set any other file to BuildAction->Resource I get the following error:

Markup file is not valid. Specify a source markup file with an .xaml extension.

.. And I seem unable to recover without deleting the solution and starting from scratch.

Here is the XAML code

<Window x:Class="WR.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Demo" Height="350" Width="300" >
<Grid>
    <ListBox Name="DemoListBox" Margin="15">
          <Image x:Name="Image1" Source="/resources/facebook.png">
          </Image>
    </ListBox>
</Grid>

Thanks in advance

Flashheart
  • 103
  • 1
  • 8

1 Answers1

6

BuildAction->Resource should be set for file facebook.png

King King
  • 61,710
  • 16
  • 105
  • 130
Art Base
  • 1,739
  • 3
  • 15
  • 23
  • +1 - this is going to be the shortest accepted answer on SO, please don't try editing to make it longer. – King King Oct 21 '15 at 00:59