Silverlight : Implementing Images - wpf

I just created a puppet in Microsoft Blend consisting of imageboxes that are displaying a dummy image(Which is a white box). In blend it shows the images but in visual studio (and when running the application) the images aren't showing.
This is a snippet of the code I am using
<Image Source="/Images/BodyParts/dummy.jpg" Height="10" Width="20" Stretch="Fill" OpacityMask="{x:Null}" x:Name="backFoot" Canvas.Left="41.71" Canvas.Top="147.668" />
alt text http://img26.imageshack.us/img26/1401/blendvscomparewo7.jpg
Please note that the circles you are seeing in both versions are different controls not images.

Be sure your picture "dummy.jpg" appears in the solution explorer within the correct folder
example:
Solution Explorer http://img403.imageshack.us/img403/4976/solutiontm2.jpg
And if you right click -> properties on the image, you should see the "Properties" window.
Then set the "Build Action" to "Content" as shown below:
Properties http://img338.imageshack.us/img338/9166/propertiesfl9.jpg

Related

Way to use WPF Image without attaching image at runtime

I know how to attach an image to a XAML <Image> via VB.net runtime code. How would I do this the normal old way. (Attach the image within the IDE without using any code)
Before WPF one would browse for the image (in the Visual Studio IDE) it would somehow place it in the project and it would work.
Now I do this same thing, I can see the image in my Visual Studio IDE but during runtime the image appears blank.
How would I use the VS IDE to correctly browse for the image so it will display at runtime? Perhaps im doing something wrong a bit of help or any guidance would be awesome
I suppose you have a folder in your project which contains your image files, in that case something similar to <Image Source="/WpfApplication1/component;ImagesFolder/ImageName.png" /> would do the trick.
If you're looking for a non-code way, when you click on tag, you can browse for imported files from Source Property from Properties panel

Expression blend 3 wont show Background image

i am developing a solution using Expression blend 3 and i have a problem because my background images wont show up in design time, in run time i can see them.
As you can see in the attached picture there is no image in stackpanel.
Is there a solution to this?
Best regards,
Luka
In blend you should be able to just drop and drag the image onto the workspace from your projects folders, blend then adds the xaml on the fly. If its not in your project folder you should create a images folder and "add existing item" then browse to the image.

Silverlight background image

My problem is that the image only ever shows in the designer. It always shows there no matter what method I try, but once I actually start the program it's nothing but white.
My XAML code:
<Grid.Background>
<ImageBrush ImageSource="C:\Users\Martin Clemens Bloch\Desktop\Mappe of
Text\DTU\Bachelor\Silverlight\OrgOS\OrgOS\Data\BackgroundS.jpeg"/>
</Grid.Background>
The Grid in question is at the very front so there should be nothing "blocking the view" to the background image,
The image has been added to the project and I have tried different build actions including "resource", "content" and "embedded resource" combined with "copy always" and "do not copy".
I have also tried a relative path of "/BackgroundS.jpg" while placing the image in the clientbin with the XAP file.. and other places.
I also tried putting the image INSIDE the XAP file by renaming the xap to zip and then back after putting the image.
I have also restarted VS2011.
Some I tried on my own, other stuff after numerous tutorials and stackoverflow questions.
Now we are talking about an IMAGE here, what am I doing so wrong!?
You need to include your image as a Resource in the silverlight project, and reference it like this:
<ImageBrush ImageSource="/The.Assembly.With.Images;component/the/path/to/the/images/myimage.png"/>

Image in ComboBox only visible in designer

Here's the situation:
I have a combobox within a button,, In expression blend when I add image to combo box item with the cod below, there's no problem apparently, image and textblock are showing well but as I run the proj.((F5)) there'e no sign of image, What I'm doing Wrong???
here's the code I use to add the image:
<ComboBoxItem Background="LightCoral" Foreground="Red"
FontFamily="Verdana" FontSize="12" FontWeight="Bold">
<CheckBox Name="CoffieCheckBox">
<StackPanel Orientation="Horizontal">
<Image Source="coffie.jpg" Height="30"></Image>
<TextBlock Text="Coffie"></TextBlock>
</StackPanel>
</CheckBox>
Any help Is much appreciated...
One likely problem might be that the image file is in your project folder without being copied to the build folder; /bin/Release for example. The application then will not find the file anymore. You can either ensure that the image is being copied when the application is compiled (that alone may not work actually as unqualified URIs make the parser look for resources as far as i know, the designer however does not seem to care) or you can embed the image as a resource. I do not know how to change compile settings in Blend however as i only use Visual Studio...
I had a similar problem showing images (used Uri strings) in a listview in a Silverlight application. They appeared properly in Expression Blend, but were not visible when I started it from Visual studio.
I kept my images in a folder called Images in my project, by setting the "Build action" for my image properties into "Content" fixed the problem. Now they show up when running the application. Hope it helps!

Weird UserControl image path behaviour in Blend 4 and WPF 4.0

I'm using Blend 4 and VisualStudio 2010 to build a kiosk WPF 4.0 app that has a wizard-like function. I've decided I'd like individual steps moved to separate UserControls, to keep the main window of the application as lean as possible. However, I'm having trouble including the UserControl into the main window, since image paths are being mangled after moving the XAML to a separate UserControl file.
This code works when it's put into the main window XAML:
<Button Grid.Row="1" Grid.Column="2" Height="{Binding ActualWidth, RelativeSource={RelativeSource Self}}" Margin="20" VerticalAlignment="Bottom" Style="{DynamicResource ImageButton}">
<Button.Background>
<ImageBrush ImageSource="/Images/Extra/motor_boat_2.jpg" Stretch="UniformToFill"/>
</Button.Background>
</Button>
But when I move that code to a separate user control and include it in the main window, the designer throws and exception:
IOException: Cannot locate resource 'images/extra/sailing_boat.jpg'.
I've tried using a couple of different syntaxes, but all fail, sometimes using the %ProgramFiles% directory, other times converting the absolute path to relative (as above). Sometimes, the Build Project operation in Blend 4 fails because of this.
All the images are marked as Resource with Build Action set to Copy Always.
VisualStudio has no problem building and running the application, the UserControl displays correctly within the running application with no thrown exceptions.
EDIT:
Using relative paths in the UserControl and then building and running the app from VisualStudio and switching back to Blend correctly displays the images, until the next modification to the UserControl.
Use Pack URI like following:
Uri uri = new Uri("pack://application:,,,/Images/Extra/motor_boat_2.jpg");

Resources