When you create a Silverlight Business Application you get a Silverlight application and a Web application. In the Web/Resources folder of the Silverlight app there are links to the files in the Resources folder of the Web app. These links are exactly like the files they link to in that they are heirarchical with the Resource.Designer.cs file shown as a code-behind file for the Resource.resx file
When I try to link to a Resource file in this way I only get the .resx file unless I link to the .Designer.cs file separately. However in this case the Designer.cs file is then shown as a standard code file and not related to the .resx file.
Does anyone know how to do this linking correctly?
After you add a link to new resource file without *.Designer.cs, set its property "Custom Tool" ("PublicResXFileCodeGenerator").
Related
I have a directory of HTML files and images added as resources in Visual Studio; these files link to each other.
I can load any one of them as a stream or string and load them up into the WebBrowser, but if I do that, hyperlinks between the files break, because the document no longer knows that it's in a directory with other files.
I don't want to load the files as file:// URLs on disk, because they also contain JavaScript; by default IE blocks them from running active content.
How do I load these files in a WPF WebBrowser?
I've got a WPF application I'm building. The solution contains a WPF control library project called CustomControls. There's a folder under the CustomControls project folder called Layouts. There's an XML file in that folder called OnscreenLayout.xml. The Build Action property for this file is set to Embedded Resource.
I'm trying to load that file into a stream in the code behind and pass the stream on to a method of a third party library class. The code in question looks like this:
OnscreenKeyboard.DefaultLayout = FPS.VirtualKeyboard.KeyboardLayout.Create(
App.GetResourceStream(
new Uri( #"/CustomControls;component/Layouts/OnscreenLayout.xml",
UriKind.Relative ) ).Stream );
When this code runs, it throws an IOException with the message
Cannot locate resource 'layouts/onscreenlayout.xml'.
I've even tried using this string for the Uri:
#"pack://application:,,,/CustomControls;component/Layouts/OnscreenLayout.xml"
But no joy. What am I doing wrong?
Edit: I have even tried changing the build action for the file from "Embedded Resource" to "Resource" and it still doesn't work.
Thanks
Tony
Only Content and Resource build actions are valid for resource files used in WPF application.
Please avoid other build actions such as Embedded Resource - this will work as well with appropriate API, but it is not favored by WPF.
I have a Silverlight app made in Visual Studio 2010 and I want to put it on a website but I don't have the slightest clue how.
I've looked at all the msdn documentation and they all mention a .xap file that is the file you use on the website but there is no .xap and I can't find out how to compile my code into a .xap file.
Also, when I run the App and look at the source in the browser, it has my code compiled into the .xap file, but there is no .xap file!
So my question is simply how do you go about getting a Silverlight app on a website because I've been trying for hours and I can't figure it out.
A sample html or aspx page is included when you create the solution. This is the page that the browser navigates to when you hit F5. You can take that page as a basic example of how to embed a Silverlight app in a page. You should find it in the project folder.
Silverlight projects are commonly built into a XAP file when you hit "Build" in VS. This file lives in the bin/Release or bin/Debug folder and basically contains your whole application.
Steps to create a silverlight application Hosted in a web site,
Select Silverlight Application Template while adding new project in VS2010
When you click Ok, ensure that Host the Silverlight application in a new web site is Checked.(It will create a new ASP.Net web application to host the Silverlight)
If you haven't checked the Host the Silverlight application in a new web site option, you can add a new ASP.Net Web application project and then go to its properties and select Silverlight Applications option in left pane. Then Click Add, select your Silverlight Application to be hosted and click ok. You are done now.
But If haven't selected the Silverlight Application Template, then you might have created a Silverlight Class Library. It wont generate any xap file. It just gives a dll. So you need to recreate a project as mentioned above.
I believe that in Silverlight whenever you create a project, right at the beginning, it will ask you if you want to create a web app automatically. If you chose yes, something like YOUR_PROJECT_NAME.web will be created, go into that folder, you will find a folder called ClientBin.
The .xap file will be inside that folder.
HTH
I'm new to WPF, and created a 1st simplistic WPF application that I want it to run in a webbrowser, IE or Fox.
1 - Within the Visual Studio project, I created a /Images folder with a few .jpg files
On the WPF xaml form I have 1 image and 1 button.
When application starts, the image displays /Images/img1.jpg
When User clicks the button the image must display /Images/img2.jpg
How can I force the VS publisher to include the Images folder? Apparently I can't see it in the ApplicationFiles ?
2 - Though I was able to program and run this small app on my local computer, I'm getting lost when it comes to deploying to my hosting ASP where I have a Windows hosting account that runs .NET 3.5!
From Microsoft WPF website they say I shall deploy 3 files:
"The Application Executable .exe
The Deployment Manifest .xbap
The application Manifest .manifest
The .xbap file contains the information that ClickOnce uses to deploy the application and has the .xbap extension."
But I can's see no .xbap files at all within the published stuff!!!
Any clue please?
To answer your first question:
The images will be embedded in the compiled application, so you will not see the images in the application files.
Note:
The build action of images added to your project is 'Resource' by default - leave this as is.
Do not use the resources tab in the Project properties window, just drop and drag the images into the Images folder in the solution explorer.
To help answer your second question:
Did you create the project as an WPF Browser Application?
In your .csproj file you should see the following:
<HostInBrowser>true</HostInBrowser>
<Install>False</Install>
<ApplicationExtension>.xbap</ApplicationExtension>
<TargetZone>Internet</TargetZone>
If not, just recreate the project as a WPF Browser Application and copy your files from the existing project to the new one.
I want to use localization feature for Validation messages, for eg-
[Required(ErrorMessageResourceName = "RequiredField", ErrorMessageResourceType = typeof( ))]
public string someText
{ get... set...}
I'm using MVVM pattern so this property is in my model(its a differnt project inside same solution of silverlight) and all my localization resources are in the App.current.Resources. How can I set the ErrorMessageResourceType to my App resources?
Please suggest.
Thanks in advance
Sai
Well apparently Localization of error messages isnt as straightforward. You are supposed to add a resource file to the MyApp.Web project, that is the asp.net site that hosts your silverlight app, then add that resource to the silverlight app, then you will be able todo the code you stated in your question after some tweaks, follow the instructions below
This section explores how error
messages can be localized by storing
them in resource files and sharing
them across tiers.
The example uses .NET RIA Services
walkthrough project as the base
project and builds on top of it.
Let's say we want to add a validation
error as a resource for LoginID field.
Create a new ‘Resources' folder in the HRApp.Web project
(server project)
Add a new resource file to this folder and name it
ValidationErrorResources.resx
Double click on the .RESX file to bring up resource designer
page
Add a new string resource with Name= LoginIDValidationError and
Value= "LoginID field is required"
Change the access modifier to ‘Public' by clicking on the ‘Access
Modifier' drop down UI and selecting
‘Public' and save the project. This
generates a ValidationErrorResources
class in the HRApp.Web.Resources
namespace.
Open ‘OrganizationService.metadata.cs' file
and add the following ‘Required' field
validation to LoginID member. Specify
the error message resource name and
resource type values by setting the
corresponding attribute members as
shown below.
[Required(ErrorMessageResourceName =
"LoginIDValidationError",
ErrorMessageResourceType =
typeof(ValidationErrorResources))]
public string LoginID;
Now we want to share this resource
file in the Silverlight project
(client project). To do this,
Create a folder Web\Resources in the HRApp project
(folder structure must match the
resource file namespace on the server
side)
Select Resources folder and bring up Add Existing file dialog,
browse to the server side resource
file folder location
Select ValidationErrorResources.resx and
ValidationErrorResources.designer.cs
files, and add them as link files to
the Silverlight project. Save the
project file
Open HRApp.csproj file in notepad , locate the section where
.designer.cs file is included and add
the highlighted 3 lines to this
section
<Compile
Include="..\HRApp.Web\Resources\ValidationErrorResources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>ValidationErrorResources.resx</DependentUpon>
<Link>Web\Resources\ValidationErrorResources.Designer.cs</Link>
</Compile>
Save the project file and reload the project in Visual Studio
Build the solution and run
Now whenever the validation fails for
the LoginID field the error message
from the resource file is shown to the
user. The resource file can now be
customized to store locale specific
error messages.
This solution almost worked for me. I had to made some arrangements to work with a data model (edmx) located in one project, DataDomainService (Ria) in other and the Silverlight access layer in other project.
When i compile the HRApp equivalent in my situation, the metadata containing the validation info for some property is not generated. It says that the client has no access to the ValidationErrorResources type. But after following all the instructions mentioned above plus some others to get a correct resource namespace, the client CAN access ValidationErrorResources.
It works if i write it myself to the generated Silverlight class.
So seems like this kind of project separation is not quite supported by the class generator...
But thanks anyway, this post was quite helpful and maybe i'll make it all work in a couple of days.
:D
When I did this recently this thred helped alot: http://forums.asp.net/t/1433699.aspx
In particular "...the resource file must be converter to a class before being able to reference it in the typeof of the ErrorMessageResourceType in the data annotation..."
Also there are a few other useful hits from the main search engines: http://www.liquidjelly.co.uk/supersearch/?q=silverlight%20dataannotations%20localization&lang=en-GB