views:

893

answers:

2

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:

  1. How do I go about hosting a web page inside my WPF app
  2. How could I hide/remove buttons based on whether I'm inside my WPF app vs. inside something like IE explorer?
  3. 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?
  4. 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!

+1  A: 

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>
 <a href="#" onclick="OnClick()">Click me</a>
</body>
Yordan Pavlov
A: 

o, and you should add saved from url=(0014)about:internet comment above the head tag to make IE not block the javascript

Yordan Pavlov