Coding Web Browser for Windows 10 IOT on Raspberry PI 2
by novaspirittech in Circuits > Raspberry Pi
9758 Views, 24 Favorites, 0 Comments
Coding Web Browser for Windows 10 IOT on Raspberry PI 2
![/code - Web Browser For Windows 10 IOT on Raspberry PI 2](/proxy/?url=https://content.instructables.com/FCT/EQIW/IEV86EVS/FCTEQIWIEV86EVS.jpg&filename=/code - Web Browser For Windows 10 IOT on Raspberry PI 2)
As per the the video tutorial you would need to download Visual Studios 2015 Community
Lets Look at the Code
![2015-09-21-1512-36.00_03_36_27.Still001.jpg](/proxy/?url=https://content.instructables.com/FPK/DBD2/IEV86GFO/FPKDBD2IEV86GFO.jpg&filename=2015-09-21-1512-36.00_03_36_27.Still001.jpg)
The code for this sample is pretty simple:
- An embedded webview control
- TextBox as address bar
- Go Button to start Navigation
when go button is pressed we call a web navigation helper method to do the actual navigation
UX Code
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <Grid.RowDefinitions> <RowDefinition Height="65"></RowDefinition> <RowDefinition Height="*"></RowDefinition> </Grid.RowDefinitions> <!--Address bar--> <StackPanel Grid.Row="0" Orientation="Horizontal"> <TextBox x:Name="Web_Address" FontSize="24" TextWrapping="Wrap" Text="http://www.youtube.com" VerticalAlignment="Center" VerticalContentAlignment="Center" Height="54" Width="958" KeyUp="Web_Address_KeyUp"/> <Button x:Name="Go_Web" Content="Go!" HorizontalAlignment="Right" VerticalAlignment="Center" Height="60" Width="107" Click="Go_Web_Click"/> </StackPanel>
<!--Web view control--> <WebView x:Name="webView" Grid.Row="1" /> </Grid>
Main Code C#
private void Go_Web_Click(object sender, RoutedEventArgs e)
{ DoWebNavigate(); }private void Web_Address_KeyUp(object sender, KeyRoutedEventArgs e) { if (e.Key == Windows.System.VirtualKey.Enter) { DoWebNavigate(); } }
private async void DoWebNavigate() { try { if (Web_Address.Text.Length > 0) { webView.Navigate(new Uri(Web_Address.Text)); } else { MessageDialog dlg = new MessageDialog("you need to enter a web address."); await dlg.ShowAsync(); } } catch (Exception e) { MessageDialog dlg = new MessageDialog("Error: " + e.Message); await dlg.ShowAsync();
} }