Changing Silverlight Application name dynamically - silverlight

I'm creating a deployable module where some parts are written in Silverlight, and I'm making the SL application deployable for OOB usage. However, I want to make Silverlight take the name of the website that it's deployed from, such as, when a user installs it from Example.com, I want to have "example.com application" with the site's own icon in the shortcut. Is there any "supported" method of doing this, or will I be going with locating the XAP file and manually changing AppManifest.xaml inside it?

You will need to find out your URL of your application:
string appURL = Application.Current.Host.Source.AbsoluteUri.Substring(0, Application.Current.Host.Source.AbsoluteUri.IndexOf(#"ClientBin/"));
So this will solve the title problem, next is the icon. You could load the image from the page:
Uri uri = new Uri(String.Format("{0}/favicon.png", appURL));
IconImage.Source = new BitmapImage(uri);
It's not perfect, you will have to manipulate appURL to get the domain name only.

Related

richimage component src value does not work with uri value

When I set uri string value into richimage src property, I can not see the image on application ui.
If I try to paste the value into browser it shows the image
ie: file:/C:/Users/Dijitaluser/AppData/Roaming/JDeveloper/system11.1.1.6.38.61.92/o.j2ee/drs/IncomingPaperWorkWebApp.war/WEB-INF/classes/com/acme/resource/images/upload_file.png
As a matter of fact, if i put the image file into the same project as you say image/thefile.png, that's ok. But I use distributed resources project and I get the uri by using resourceBundle. So this solution is useless for me.
I' m trying to test application on my integrated weblogic server, and this uri which is returned by resourceBundleHelper, is already validated by browser. Could you plz give me some suggestions about the issue.
I trasnformed my resources project to web project to use web.xml about defining resources servlet. Then moved my all images in META-INF/adf/images and added into my VisualResourceBundle(extends ListResourceBundle) class.
It works
http://www.oracle.com/technetwork/developer-tools/adf/learnmore/86-images-from-jar-427953.pdf
hope it helps

How to use a Silverlight Solution

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

What if we don't host our silverlight Application when we first Create it?

As we all know very well..
whenever we create application inside silverlight it is asking us for hosting it
by dialogue box at given below.
My question is what if i unchecked the check box[Host the silverlight application in a new web site].
Means what kind of problem we have to face later if I don't host our Silverlight Application in any of the option given by dialogue box.
Basically it is not a problem at all. You can add a website at any time later.
In the project settings of a website there is a Silverlight tab. Under that you will find the option to add Silverlight projects to the website. This will setup the links to generate the XAP in ClientBin as well as giving you the option to create test pages for each Silverlight app added. The test pages will give you the sample JS you need to host your Xap later.
You will have to eventually host your application somewhere otherwise it will stay on your local harddrive and hardly reach any clients. So if you have an existing web site you could simply copy-paste the necessary javascript to this site later in order to embed your Silverlight application. In this case you can uncheck this checkbox.

WP7 set Image to source behind a HttpBasicAuthenticator

i am trying to set an image in a Windows Phone 7 App, there is a problem thoug, the url where the image is located required Authenticator, i have a valid username and password, but i have no idea how to load the image thoug an URI with the Authenticator?
ProfileImage.Source = new BitmapImage(new Uri(userObject.ProfileImage));
Unless you can use a authentication url, ie. http://username:password#domain.tld/image.png then you need to download the image locally first, and then load it afterwards.
You could write a custom handler for it, that downloads it to the Isolated Storage, and then automatically updates the UI, while using a fallback image (typically blank) while loading it.

Silverlight Asp.Net project integration

I added a Silverlight application to my ASP.NET website. Visual Studio made a new silverlight project and added its xap to the ClientBin folder under the project of my website. So both the projects are under one solution.
My Silverlight app is supposed to read an xml file and I was unable to make it access the file from the client bin folder under the website project. Adding a reference to that project does not work since it says only references to other silverlight applications can be added. Right now its working when the file is under the silverlight project but not when it is under the website project.
how can I make it read the file from website project?
The project structure is
WEBSITE1 (solution)
-WEBSITE1 (project)
-ClientBin
-file0.xml
-silverlightchart.xap
-SilverlightChart
-file1.xml
I can access file1.xml using
XDocument document = XDocument.Load("file1.xml");
I want to access file0.xml but no path works for me, for e.g,
XDocument document = XDocument.Load("~/ClientBin/file0.xml");
and WEBSITE1 is the startup project
You should be able to read a file from the ClientBin folder simply enough without needing to do anything special. At a guess I would say the you have accidentally set the Silverlight application as the startup project. In this scenario you want the website to be the startup project then either have the Silverlight apps test page marked as the start page or to navigate to the silverlight page once the browser has started.
Edit
The problem you have is that the Load method is synchronous but Silverlight does not support synchronous access to web resources. Hence passing a Uri to the Load method will only work if the that Uri can be fulfilled by content in the Xap. Thats why an Xml file in the silverlight project works because it ends up in the Xap.
To fetch Xml from the site you need to do this:-
WebClient client = new WebClient();
client.DownloadStringCompleted += (s, args) =>
{
XDocument document = XDocument.Load(args.result);
SomeFunctionToContinueWithDocumentProcess(document);
}
client.DownloadStringAsync(new Uri("file0.xml", UriKind.Relative);
// code exits here but _document won't be loaded yet

Resources