0

I can see the image while doing programming. But after execution I do not see the image. Do I need to add some tags?

<Window x:Class="DicomEditorInWPF.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="DicomImage Display" Height="350" Width="525">
<Grid>
    <Button Content="text button" HorizontalAlignment="Left" Margin="115,124,0,0" VerticalAlignment="Top" Width="75"></Button>
    <Image Name="DicomImageDisplayer" Margin="332,124,0,0" Source="SampleImage.Jpg"/>
</Grid>
</Window>
4
  • Remove margin from button and image.and try
    – Shivam cv
    Commented Dec 2, 2014 at 17:51
  • thanks but it did not help. Commented Dec 2, 2014 at 17:56
  • Is the image part of the project or is it only located in the same folder?
    – Flat Eric
    Commented Dec 2, 2014 at 18:02
  • Yes, i can see the image in the designer displayed above. but i dont see it same after execution. Commented Dec 2, 2014 at 18:08

4 Answers 4

1

Probably your image is overlapped by the button. Try putting them in separate rows.

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Width="*" />
        <RowDefinition Width="*" />
    </Grid.RowDefinitions>
    <Button Grid.Row="0" Content="text button" Width="75"></Button>
    <Image Grid.Row="1" Name="DicomImageDisplayer" Source="SampleImage.Jpg"/>
</Grid>

Or you can use a different container e.g. StackPanel or DockPanel.

2
  • i have removed button now and Added Grid.Row="1". ] Commented Dec 2, 2014 at 18:16
  • Did you add the row definitions? If so you can add both of them, just keep them on separate rows. That is the first one on Grid.Row="0" the other on Grid.Row="1" Commented Dec 2, 2014 at 18:19
0

Just place your code inside a container, can be anything Grid,StackPanel and you should be able to see the image.

0

thanks for your answers.

File must be added to the project, with the build action type of Resource.

-1

Try this working in the codebehind not in the xaml, and remove the source from xaml

BitmapImage logo = new BitmapImage();
logo.BeginInit();
logo.UriSource = new Uri("pack://application:,,,/AssemblyName;component/Resources/logo.png");
logo.EndInit();
finalImage.Source = logo;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.