I have a silverlight class library (not a top-level application) with several user controls that are shared by different silverlight applications. I have gone through and pulled out several styles and brushes for the controls and put them in a separate XAML file as a resource dictionary which I bring into each control as a merged resource dictionary. Right now this works great in my top-level applications, as long as I keep that resource dictionary as a "Resource" build action and reference it in that way from the controls.
What I would really like to do is have this resource dictionary XAML file as a "Content" build action which gets copied into the top-level XAP, so that the XAML can be swapped out in the XAP file without needing to rebuild the project. Whenever I try to set this up, the XAML file will get copied into the output bin for the class library project, but it will never get copied to my top-level silverlight application project output directory or into the final XAP file.
What is the best way to accomplish this? The XAML resource dictionary is essentially a dependency of the class library, and the class library (of user controls) is a dependency of the top-level silverlight application.
Add the ControlResources.xaml (the ResourceDictionary you want in your XAP) to the top-level XAP project as a link via Project->Add Existing Item->Add as Link (a drop down item on the Add button in the dialog), and set it to build as Content, also.
Will merged dictionaries meet your needs?
http://www.silverlight.net/learn/videos/silverlight-videos/hdi-sl3-merged-resources/
http://thoughtjelly.blogspot.com/2009/10/cross-project-mergeddictionaries-in.html
http://www.liquidjelly.co.uk/supersearch/?q=silverlight%20merged%20resource%20dictionaries&lang=en-GB
Best,
Mark
Related
I've built a user control for my Xamarin Forms projects, starting with a Xamarin.Forms Class Library. The user control contains an image file that I've added to the Class Library project in an "Assets" directory. Within the user control code's XAML I'm simply referencing the image as...
<Image Source="Assets/ImageFile.png"/>
I'm thinking there's no need for platform-specific code here since the image file is local to the Class Library project and compiled into it.
When I reference the DLL in a Xamarin Forms project, everything works as expected...EXCEPT, there's no image. It's as if the Class Library can't see it.
I've played around with the path, but the result is always the same: no image.
However, if I drop the image file into the Xamarin Forms project (i.e., into the Assets directory in UWP), the image appears just fine -- even though I'm still referencing the Class Library through the DLL.
What am I missing? Surely I can embed the image within the DLL, yes?
To make sure the image is included within your DLL:
You need to set the Build Action: EmbeddedResource.
To embed an image in a project, right-click to add new items and select the image/s you wish to add. By default the image will have Build Action: None; this needs to be set to Build Action: EmbeddedResource.
If you need to know where to set this:
The Build Action can be viewed and changed in the Properties window for a file.
You can read more here.
I have Asp.net MVC as a Class library. All of my .resx files are also in the same class library project as Embedded resource. So basically ill get output as a dll
And my requirement is that i need a page where i can get all the key value pair from the .resx files from the dll (which is bit easy) and again update the resx in the dll to reflect the changes on screen.
So the basic idea is I need a page where i can dynamically update the .resx file which are avaliable as the external class library. And the updated resources must be seen 'AS UPDATED' wherever needed.
Any Kind suggestions or some other working approach heartly welcomed.
Is it possible to create single exe file from my C# WPF project? The project contains some images and videos in Movies folder inside bin.
How can I compile all of this in singe exe file? I know it will be large in size but it is OK.
You should add this files to you project and use Build Action: Resource for this files. In this case, it will be introduced into the main assembly of application.
It will be a binary resource, because it is embedded in the compiled assembly as an opaque binary large object.
Quote from Matthew MacDonald book: Pro WPF 4.5 in C#:
There are a couple of things that you must not do in order to use assembly resources successfully:
Don’t make the mistake of setting the Build Action property to Embedded
Resource. Even though all assembly resources are embedded resources by
definition, the Embedded Resource build action places the binary data in another
area where it’s more difficult to access. In WPF applications, it’s assumed that you
always use a build type of Resource.
Don’t use the Resources tab in the Project Properties window. WPF does not
support this type of resource URI.
I want to add some xml file as resource to my class library project .
Any idea how to do so , and call it later?
In windows application i would do it like ClassLibrary1.Properties.Resources.file.xml
But here it didn't worked any idea how i do it here ?
This article explain how to use embedded resources in C#.
It boils down to
At 'Design time': Add file to project and mark it as an embedded resource (properties)
At 'Run time': Get instance of Assembly that holds the resource you want, then get that resource out as a stream.
var assembly = Assembly.GetExecutingAssembly();
var stream = assembly.GetManifestResourceStream("fully.qualified.name.of.the.resource");
If you're struggling to work out the fq name of the resource, a lazy way is to use the reflector to open the assembly that holds it. Go to the Resources folder, right click on the particular resource and choose 'Copy'.
In windows application i would do it like ClassLibrary1.Properties.Resources.file.xml
By default, the class generated to access the resources is internal, so you can't access it from another assembly. If you need to make it public, select the .resx file, go to its properties, and change the Custom tool property from "ResXFileCodeGenerator" to "PublicResXFileCodeGenerator". This custom tool generates public classes, which should solve your problem.
Right Click on Class Library Project, select properties, on tabs on the left choose Resources section.
Since your .resx files ares not recognizable by Visual Studio, add a new one.
It will create a new .resx file.
Copy all your original content and paste into new one. Then you can delete old one.
That's it!
You would need to repeat same process for your all supported languages.
Had a basic WinForm question: By default a resx file is created for every form or user control (along with the designer.cs). This resx works fine for all the controls and the text added to the controls via the UI.
I was wondering if I could use the same resx to add strings which have to be used programmatically and based on conditions, attached to the controls? Will the resx get overridden in any case and this custom strings be removed?
What is the best practice to follow in this case?
There's a strange problem with the string resources in the Resources.resx file. There's no obvious way that I ever discovered how to create a new resource table for another language with the IDE. It can be done by hand though. Follow these steps:
Project + Properties, Resource tab,
add the strings you want to use in
your program
Start Windows Explorer and navigate
to your project's Properties folder
Copy and paste the Resources.resx
file
Rename it to the culture you want to
use. For example:
Resources.fr-FR.resx
Back to VS, click the Show All Files
icon in the Solution Explorer window
Expand the Properties node, the new
resource file should be visible
Right-click it and select "Include
in project"
Select it, in the Properties window
set Custom Tool =
"ResXFileCodeGenerator"
Verify that Build Action is set to
"Embedded Resource"
Build your program. You should get a new folder in your project's bin\Debug directory with the satellite assembly, named projectname.resources.dll. This satellite assembly contains both the localized strings and any localized resource from the forms. Test that it works with code like this:
public Form1() {
System.Threading.Thread.CurrentThread.CurrentUICulture =
System.Globalization.CultureInfo.GetCultureInfo("fr-FR");
InitializeComponent();
textBox1.Text = Properties.Resources.String1;
}
The auto-generated ones get overwritten (I'm using 2005), so no I would not use the same file. I would suggest creating a separate area in your project for .resx files like this. Usually I create one .resx per form, matching the name, of course.
Edit: Here is a more detailed answer I gave recently to organize the file/folder structure when localizing your app with .resx files.
Or you can try this:
Add this code in main();
using System.Resources;
ResXResourceWriter rw = new ResXResourceWriter("Resources.de-DE.resx");
rw.AddResource("String1", "de");
rw.Close();
...
repeat for more files
Go to the bin directory and move the XML (resx) file(s) to perhaps the property folder.
Go to Step 5-9 above in nobugz post.