I know this may sound pretty dumb but how do I add a new webpage to the Silverlight Project?
I did a "Add new Item" and select an xaml file.
Now I want to open that file via the webbrowser. The File is called PrintPage.xaml.
private void Button_Click_1(object sender, RoutedEventArgs e)
{
HtmlPage.Window.Navigate(new Uri("PrintPage.xaml" , UriKind.Relative), "_blank");
}
Page not found error.
Xaml pages are Silverlight Pages, not Web pages. With Silverlight you are always on the same Web page, but displaying different Silverlight pages internally within the Silverlight object.
If you want to change Silverlight pages, start with either the Silverlight Navigation App or Silverlight Business App templates as an example. The Silverlight navigation systems all work using browser "bookmark" links (they have a # at the end of the HTML page) and use the parameters after the # to determine the target page. By using bookmark links the hosting web page does not get refreshed (otherwise the Silverlight application would reload).
If you actually want to go to a new web page, with a new Silverlight application, you want to add an ASPX or HTML page instead and browse to that.
Use this code
HtmlPage.Window.Invoke("ShowBrowserIFrame", url);
url is path of your hemp page, and ShowBrowserIFrame is java script function, used to open html web page.
function ShowBrowserIFrame(url) {
BrowserDivContainer.css('display', 'block');
$('<iframe id="' + jobPlanIFrameID + '" src="' + url + '" style="height:100%;width:100%;" />')
.appendTo(BrowserDivIFrameContainer);
slHost.css('width', '0%');
}
Follow this link to add html page inside silver light project.
Related
I am having a my problem is I can not redirect my page in silverlight like most of people who are not familiar with this technology .
I design a login page first and if password is correct I want it to direct to MainPage.xaml
as you can see I tried methods which are commented already it did not work . I searched in this web page there are some posts about this problem but I could not solve please help me .
when i try that one;
Uri target = new Uri("MainPage",UriKind.Relative);
NavigationService.Navigate(target);
error message : Object reference not set to an instance of an object.
actually we found a solution with my friend ;
instead of directing a web page , when code goes into if block we are changing the content of page with {this.Content = new MainPage() ; } method and it is working .But System.Windows.Browser.HtmlPage.Window.Navigate(target) this one is directing us same login page or pages like www.---.com outside normal html pages .
Normally you need to use the NavigationService to do this:
NavigationService.Navigate(new Uri("/MainPage", UriKind.Relative));
The NavigationService is a property on the Page object so it will be available in the Login code-behind.
However, after you mentioned that you've "already done this" I realized the issue. Silverlight Navigation uses a Frame control. This Frame control lives in MainPage.xaml for the default project. So you're not navigating inside the frame, but you want to change the entire screen to a different one and do so without the Navigation services built into Silverlight.
I'd suggest you either (a) have the Login run as a page inside of the Frame on MainPage (you can load or unload the links on the top based on if the user is authenticated) or (b) don't use the Navigation for the remainder of the application and use a framework like Caliburn.Micro to handle all the Navigation between views.
I am totally to Silverlight and am Getting started. I finished the first of the Getting started series here and now seeing into HTML Bridge now over here. Visual Studio created a website for me when it created the new silverlight application. For the HTML bridge tutorial I created another silverlight page(Is this what i should create) and put some code into it.
Question
How do I embed this into a html page? ( I know how to do it using markup as well as javascript, I am confused as to how to get the application out of single xap file inside ClientBin directory)
With Silverlight you are dealing with a single plugin within a HTML page. That plugin is the single XAP file that the HTML page downloads.
Your Silverlight app may also have many pages, but its navigation is not the same as HTML navigation (it uses bookmark URLs to fool the browser into staying on the same page while it changes content). There is only the one HTML page involved.
Initially, just to test your new page, you can change the app.xaml.cs file to create your new Silverlight Page instead of RootVisual = new Main() etc. Long term you need one Silverlight application per separate plugin your require.
Update (from comments):
Pages in Silverlight are changed by substituting a visual element of the single main page with the contents of another Silverlight page.
You cannot simply replace the RootVisual (as that can only be set at startup).
Start with a new Navigation or Business application project to see the basics (navigation adds a lot of complexity, but once you see how it works it is pretty cool).
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.
In my silverlight application I want to open a xaml in a new web browser. how can I do that?
with HTMLPage.Window.Navigate it is just aspx pages - maybe I can convert xaml to aspx?
10x!
a XAML page cannot be shown in a browser window. What Silverlight do actually is showing the Silverlight program within an < object > tag in the aspx (or html) page; nothing more.
In your silverlight project, if you chose to host your project in a new web site, you will see a second project with both a htm and aspx file that hosts that object that links to your xap file.
So basically, you need to create a second Silverlight project that will be hosted in a different aspx page. Then in your main silverlight project your can open that new aspx page in a new web browser window.
I need to create a Web-based Dashboard tool for a LOB application. Essentially users need to be able to log in to a web-site which will allow them to view stats for various bits of data, as well as see any notifications that pertain to them. Our primary application is built for the desktop using WPF. We also need to provide an identical dashboard that will be hosted in our WPF app. The main difference being that in the WPF version they will have buttons that will open up other parts of the application to make changes to the data, or perform whatever actions are necessary.
The main issue is that management only wants to write 1 version that can be used both on the web and in the WPF shell. They don't want to write to different version of the UI. So the solution would be to write the dashboard for the web, but host it inside our desktop application for local users, and in the browser for remote users.
So here's my questions:
How do I go about hosting a web page inside my WPF app
How could I hide/remove buttons based on whether I'm inside my WPF app vs. inside something like IE explorer?
If links or buttons are clicked inside the browser, how can the WPF app react to those clicks and open the pertinent screen inside the app?
What's a better approach?
I realize this idea is probably bad so don't flame me for it. I'm simply trying to supply management with the right approach. All suggestions are welcome.
Thanks!
You can host a web page in a WPF application using the WebBrowser controls that was added in .NET 3.5 SP1:
<Grid>
<WebBrowser Name="browser" />
</Grid>
And in the code-behind you have to set the Uri to your page and an object (which should be com-visible) that is to be called from the java script:
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
string uri = AppDomain.CurrentDomain.BaseDirectory + "TestPage.html";
this.browser.Navigate(new Uri(uri, UriKind.Absolute));
this.browser.ObjectForScripting = new ScriptingHelper();
}
[ComVisible(true)]
public class ScriptingHelper
{
public void ShowMessage(string message)
{
MessageBox.Show(message);
}
}
}
And finally in your page you must call the code using window.external like below:
<head>
<title></title>
<script type="text/javascript">
function OnClick()
{
var message = "Hello!";
window.external.ShowMessage(message);
}
</script>
</head>
<body>
Click me
</body>
o, and you should add
saved from url=(0014)about:internet comment
above the head tag to make IE not block the javascript