0 votes

vb.net - image not displayed when running WPF

Hello, I have the following design:

<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:WpfApplication2"
    mc:Ignorable="d"
    Title="MainWindow" Height="350" Width="525">

<Grid Margin="0,0,0,0" Background="CadetBlue">
    <Border BorderBrush="DimGray " BorderThickness="2,2,2,2" Background="AliceBlue" Padding="5" CornerRadius="28" Margin="52,0,155,219" Height="52" VerticalAlignment="Bottom">
        <DockPanel HorizontalAlignment="Left" Height="46" LastChildFill="True" Margin="-2,-1,0,-7" VerticalAlignment="Top" Width="275">
            <Image x:Name="image" Height="46" VerticalAlignment="Top" Width="41" Source="pack://siteoforigin:,,,/Resources/user (1).png" />
            <TextBox BorderBrush="Transparent" x:Name="textBox" TextWrapping="Wrap" Text="TextBox" DockPanel.Dock="Right" Width="234" Height="40" VerticalAlignment="Top"/>
        </DockPanel>
    </Border>
</Grid>

introducir la descripción de la imagen aquí

But I have problem when executing, because it ignores the image and only shows this: introducir la descripción de la imagen aquí

introducir la descripción de la imagen aquí

I add that when adding the image I did it as a resource. What is the problem? How can I solve it?

0voto

Carlos Adrián Points 263

The file "pack://siteoforigin:,,,/Resources/user (1).png" almost certainly does not exist. When you use siteoforigin instead of application, you have to copy the file to the path you indicate (with respect to the executable).

Check that the file exists, that it really is called user (1).png (with space in between), and try application instead of siteoforigin, since you say you have added it as a resource.

I think this information will come in handy: https://msdn.microsoft.com/en-us/library/aa970069.aspx#The_siteoforigin_____Authority

0voto

Lazaro Kelsy Points 197

Try setting this address only:

 Source="Resources/user(1).png"

It has happened to me that when I press F5 the images do not load. However with Ctrl + F5 everything runs OK.

HolaDevs.com

HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by:

X