MOBILE

Windows Phone 7 Development : Using a WebBrowser Control to Display Dynamic Content

2/5/2011 5:09:26 PM
Suppose now that the user enters "Ford" in the text box of the photo browsing application developed in the previous section. Unless you query the user, you won't know whether the user meant "Ford Mustang" or "Ford F-150." One way to find out would be to create a page with HTML markup and display it to the user, asking for more information. You could then save the generated file to Isolated Storage, and load it using the technique described in the previous section (Using a WebBrowser Control to Display Local HTML Content). But that would certainly be a cumbersome approach for such a simple task. Luckily, there's a much easier way to show a dynamically generated HTML page: using the NavigateToString() method of the WebBrowser control. This method takes a single argument—a string—that contains all of the HTML needed to display the page you have in mind in the WebBrowser control.

The next walkthrough shows just how easy it is to use this method.

  1. Bring up the MainPage.xaml.cs file in the code editor (either by double-clicking it or clicking the MainPage.xaml file in the Solution Explorer and choosing View Code).

  2. Next, you will construct the HTML code to display to the user. Make the button1_Click method look identical to the following code—notice how NavigateToStringloads up what amounts to a basic HTML page directly into the WebBrowser control, without your having to save this HTML to the Isolated Storage. Also note that building an HTML string in code becomes a bit ugly very quickly, so NavigateToStringshould not be abused for large HTML messages/files.

    webBrowser1.NavigateToString(@"<html>
    <body><center><div style='font: Arial 12px;'>
    Which Ford
    model would you like to see?<br><br>
    <a href='http://www.bing.com/images/search?q=cars+Ford+Mustang'>Ford
    Mustang</a> or <a href='http://www.bing.com/images/search?q=cars+Ford+F150'>Ford F-
    150</a></div></center></body></html>");


  3. Press F5 to run the application. Now if you type "Ford" in the text box and press the "Show It!" button, you should see a dynamically generated HTML message with hyperlinks asking you to clarify which Ford model you would like to see, just like Figure 1.


Figure 1. Showing dynamically generated HMTL content

Many web-based applications have been built, from translators to elaborate e-commerce systems, and all of them are easily accessible and could even be potentially enhanced with the use of the WebBrowser control on Windows Phone 7. But the WebBrowser control can do even more: in the next section, we will learn how to save the web pages locally, so that we can potentially parse certain information or search within them.

Other  
  •  Windows Phone 7 Development : Using a WebBrowser Control to Display Local HTML Content
  •  Windows Mobile Security - Networking
  •  Windows Mobile Security - Local Data Storage
  •  Windows Mobile Security - Permissions and User Controls
  •  Windows Phone 7 Development : Using a WebBrowser Control to Display Web Content
  •  Windows Phone 7 Development : Adding a WebBrowser Control
  •  Programming the Mobile Web : Content Delivery (part 3)
  •  Programming the Mobile Web : Content Delivery (part 2) - File Delivery
  •  Programming the Mobile Web : Content Delivery (part 1) - Defining MIME Types
  •  iPhone Application Development : Using Switches, Segmented Controls, and Web Views (part 3)
  •  iPhone Application Development : Using Switches, Segmented Controls, and Web Views (part 2)
  •  iPhone Application Development : Using Switches, Segmented Controls, and Web Views (part 1)
  •  iPhone Application Development : Using Advanced Interface Objects and Views - User Input and Output
  •  Windows Phone 7 Development : Wiring Up Events to an Application Bar ( part 2)
  •  Windows Phone 7 Development : Wiring Up Events to an Application Bar ( part 1) - Reacting to Add Button Events
  •  Adding an Application Bar to a Windows Phone 7 Application (part 3) - Adding an Application Bar Using Managed Code
  •  Adding an Application Bar to a Windows Phone 7 Application (part 2) - Adding a Local Application Bar Using XAML & Adding Menu Items
  •  Adding an Application Bar to a Windows Phone 7 Application (part 1) - Adding Images for Use with Application Bar Buttons & Adding a Global Application Bar Using XAML
  •  iPhone Application Development : Creating and Managing Image Animations and Sliders (part 3) - Finishing the Interface
  •  iPhone Application Development : Creating and Managing Image Animations and Sliders (part 2) - Adding an Image View
  •  
    Top 10
    Fujifilm XF1 - The Stylish Shooter
    Nikon 1 V2 - Still Fast and Handles Better
    Asustor AS-604T 4-Bay NAS Review (Part 3)
    Asustor AS-604T 4-Bay NAS Review (Part 2)
    Asustor AS-604T 4-Bay NAS Review (Part 1)
    Toshiba Satellite U925t Review (Part 3)
    Toshiba Satellite U925t Review (Part 2)
    Toshiba Satellite U925t Review (Part 1)
    iBall Andi 4.5H - Pretty In White
    The HTC Butterfly - Full HD In 5 Inches Only
    Most View
    Windows 8 Special (Part 2)
    Visual Studio 2010 : Understanding Solutions and Projects (part 1)
    Record Onscreen Action In Windows
    Programming .NET Security : Hashing Algorithms Explained
    A brief history of transforming robots (Part 2)
    Zalman F1-Series 240GB - New star SSD
    The Small Screen Revolution (Part 1)
    Learn How Too... Work Faster Than Ever With Windows 8 (Part 1)
    The Xperia T - Remarkable In How Unremarkable It Is (Part 1)
    Caching User Controls
    Stay Safe On Public Hotspots
    LG 42LM660T - Slick, Good Looking ‘Cinema Screen’
    .NET Components : Configuring Permissions
    Programming with DirectX : View Transformations
    New Year Gift Guide 2013 (Part 2)
    Apple Macbook Pro With Retina Display
    Chord QuteHD – Digital-to-analogue Converter
    Windows Server 2003 : Extending IPSec Operations, Designing IPSec Policies to Meet Secure Communications Needs
    Toshiba Satellite L850-F31R Notebook - Books & Covers
    iphone Programming : Integrating Your Application - Application Preferences