First create a project in Visual Studio.
Go to File => New => Project and select Blank App (Windows Phone).
Then make a HTML file and CSS file. Then write the code that you want to display in the Windows Phone App.
The following is the HTML page code:
- <html>
- <link href="design.css" rel="stylesheet" type="text/css" />
- <body>
- <p class="first">This is demo for HTML page in Windows Phone App</p>
- <p class="second">My Name is : NeErAj KuMaR</p>
- <p class="third">My Image :
- <img src="neeraj.jpg" class="img" />
- </p>
- <p class="fourth">
- <a href="http://www.twitter.com/sainipray" >Follow On Twitter </a>
- </p>
- <p>
- <a href="https://plus.google.com/u/0/+NeErAjKuMaR1234" >See my Profile on Google+ </a>
- </p>
- </body>
- <html>
The following is the CSS file code:
- .first {
- background-color: Black;
- font-size: 20px;
- color: White;
- }
-
- .second {
- background-color: White;
- font-size: 30px;
- color: Black;
- }
-
- .third {
- background-color: GREEN;
- font-size: 20px;
- color: Yellow;
- }
-
- .fourth {
- background-color: Gray;
- font-size: 30px;
- color: RED;
- }
-
- .img {
- width: 100px;
- height: 100px;
- }
The following is the HTML page design in a browser:
Create a folder in the Asset folder in Solution Explorer and copy the HTML and CSS files and one image to the new folder.
Then open the MainPage.xaml file and drag a ”WebView” element from the Toolbox to the Windwos Phone App GUI.
The following is the MainPage.xaml file code:
- <Page
- x:Class="HTMLAPP.MainPage"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:local="using:HTMLAPP"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- mc:Ignorable="d"
- Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
- <Grid>
- <WebView HorizontalAlignment="Left" Height="620" Margin="10,10,0,0" VerticalAlignment="Top" Width="380"/>
- </Grid>
- </Page>
Create a Loaded Event on “WebView” as in the following:
Add code to the WebView event:
- private void WebView_Loaded(object sender, RoutedEventArgs e)
- {
- Web.Source = new Uri("ms-appx-web:///assets/HTML/demo.html"); ;
- }
Debug this project and the output is: