I have "WPF userControl Library" project. In it I have window which has next line of code
<Image x:Name="imgInstructionIcon" Source="images/InfoIcon.png" >
and also in project I have "images" folder which contains InfoIcon.png file. But My code didn't see this file and give next error:
Error 58 The file images/InfoIcon.png is not part of the project or its 'Build Action' property is not set to 'Resource'
When I change path to the Source=../images/InfoIcon.png I see my icon in designer but not see in runtime.
My project is part of Solution.
Try the uri pack syntac - Read more here
Set the Source="images/InfoIcon.png", BuildAction to Resource and compile the application. Now you can see in designer as well as runtime.
Try doing as the error says: select the image in the solution explorer, then in the properties set the build action to resource. It should fix your problem.
Related
I tried to set up a Icon in XAML from the Resources.resx but it cant find the resources.
Code:
....
xmlns:resx="clr-namespace:Admin_Overwatch.Properties"
Title="MainWindow" Height="400" Width="600" Icon="{x:Static
resx:Resources.TitelLogomRand1}">
Error:
"The name "Resources" doesen´t exist in the namespace...."
The courious thing is that in the autoformat it finds every icon in the Resources file. I have Rebuild it without any success and tried a new Resource folder also with no success.
Why doesn´t it find the Folder(s) ?
Edit:
I tried this tutorial also without any success, I got the same error, it can´t find the resources....
http://social.technet.microsoft.com/wiki/contents/articles/22420.binding-to-resources-resx-files-in-xaml.aspx
The Answer was to use the Assembly in addition to the normal clr:
xmlns:resx="clr-namespace:Admin_Overwatch.Properties;assembly=Admin-Overwatch"
xmlns:local="clr-namespace:Admin_Overwatch;assembly=Admin-Overwatch"
The Assembly name can be found by
Right Click on the Project name under Properties --> Application.
But the important part is that it is not possible to load the pictures from the resx in wpf that goes only in win forms.
see here:
How to use Resources.resx to link images
I had simmilar problem. Added a placeholder image to use as default ImageSource in XAML on startup. I created it trough Project+Right-Click->Properties>Resources>Add Resource>New Image etc.
Then got to Resource folder in the project, selected the image and down bellow in properties I just selected Build Action to Resource. And now it works!
I have a file for applying styles to all controls ApplicationTheme.xaml and images in Images folder.
The build action is set to resource and copy to output directory always.
<Application.Resources>
<ResourceDictionary Source="Theme/ApplicationTheme.xaml"/>
</Application.Resources>
Now similarly i give the image source in the application theme file
ImageSource="Images\SGL-BG.jpg"
However i am getting error message
"'Failed to create a 'ImageSource' from the text 'Images\\SGL-BG.jpg'.'
What am i doing wrong here ? This is the approach i see mentioned on websites. Also if i give the full path it works. It fails to detect the theme file as well when i give Theme/ApplicationTheme.xaml. I am a WPF noob and i am not able to find solution to this seemingly simple issue.
Try this:
Source="/MyProject;component/Images/SGL-BG.jpg"
I'm attempting to use a resx file to localize some strings I am using in a XAML file. I've looked around at other documentation on the web, and they all seem to recommend a two part process:
Add a clr-namespace to your window, like this:
xmlns:props="clr-namespace:PJConfiguration.Properties"
Use that namespace to localize your string like this:
Content="{x:Static props:Resources.SharedSettings}"
I've done this, and also made sure that my resource classes are public, but I still get the following error from the XAML in step 2:
Cannot find the type 'Resources'.
Does anyone know what else might be causing this problem? Thanks in advance.
In order to make the Resources visible to XAML, you have to make sure that the code generation mode for the resources is set to public. In VS, you find that setting in a ComboBox near the top of the Resources designer window.
For more information on using .Net resources in XAML, you might want to refer to these blog posts: http://wpfglue.wordpress.com/category/localization/
Check if your .resx file is the default Resources.resx file inside the Properties directory of the Application assembly. If that is, there is no reason XAML couldn't find the public class Resources from the correct namespace under local assembly.
Try to specify the assembly name in Step 2 as recommended in this answer.
I'm trying to increase the length of time that a tooltip displays in a silverlight application. I downloaded Silverlight.Controls.ToolTip from codeplex and I add it as a reference. Here is my code in my xaml:
xmlns:Controls="clr-namespace:Silverlight.Controls.ToolTips;assembly=Silverlight.Controls.ToolTips"
<Button Content="button content">
<Controls:ToolTipService.ToolTip>
<Controls:ToolTip DisplayTime="00:00:10" InitialDelay="00:00:03">
<TextBlock Text="tooltip"></TextBlock>
</Controls:ToolTip>
</Controls:ToolTipService.ToolTip>
</Button>
The code compiles. However, while running the code I get an error "XamlParseException occurred The attachable property 'ToolTip' was not found in 'ToolTipService.' Any ideas on what is causing this error? Thanks!
I had the same problem, here is how I solved it.
1) Go to: http://tooltipservice.codeplex.com/SourceControl/BrowseLatest
2) Download the Source Code
3) Copy "ToolTip.cs", "ToolTipService.cs" and ToolTipTimer.cs from
"branches\2.2.0\Silverlight.Controls.ToolTips\" into your own project somewhere.
4) Now point the xmlns to assembly on your own project where you have copied the source file into.
So basically, just use the source file instead of the dll and it will work. This has worked for me, hope it works for you.
Good Luck.
If you are referencing the ToolTip DLL from another DLL, try also adding a reference to it into you main project.
You have downloaded this DLL from web and have not unblocked it yet.
Right Click on the DLL, go to properties and unblock it.
I have created a custom control that will have a bitmap image in it. My project structure is:
Solution
ProjectName
Resources
Actor.png
The XAML I am using is:
<Image x:Name="ActorBitmap" Source="ProjectName;component/Resources/Actor.png />
However, this is not working. I have the build options on the picture set to "Resource" and "Copy Always". Can someone please explain what I'm doing wrong ?
Thanks,
Scott
I believe you just need a leading forward slash before the resource location:
<Image x:Name="ActorBitmap" Source="/ProjectName;component/Resources/Actor.png />
There is also no need to set copy to output directory to "Copy Always". Because the build action is set to Resource the image data will be in the assembly itself, and you will not be referencing it from the output directory.