简体   繁体   中英

Image not visible in WPF 2015

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

应该为文件facebook.png设置BuildAction->Resource

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM