Can Xamarin.Essentials: Browser be a part of the page?

Yongqing Huang 241 Reputation points


I would like to have Xamarin.Essentials: Browser to be a part of the page:
at the top is a entry to type in URL, plus a couple buttons.
The rest of page is for Xamarin.Essentials: Browser.
If "Search" button is clicked, Xamarin.Essentials: Browser will be activated.
Normally Xamarin.Essentials: Browser navigate to a new page.

Is there a way to keep my UI elements (entry, buttons) en Browser in ONE page?
so that user can type in URL in my entry, browser in Chrome/Firefox.

A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,302 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 69,616 Reputation points Microsoft Vendor

    Hello Yongqing,​

    Welcome to our Microsoft Q&A platform!

    Can Xamarin.Essentials: Browser be a part of the page?

    No, you can see source code of the Xamarin.Essentials: Browser in Android, Browser use Platform.AppContext.StartActivity(intent); way to open a new page. If you start Activity in Android, it will open a new page.

    If you want to keep your UI elements (entry, buttons) en Browser in ONE page? You can use SearchBar and Webview to achieve it like following layout. Use SearchBar to input url, use webview to show webpage.

                   <SearchBar x:Name="webviewSearch" SearchButtonPressed="webviewSearch_SearchButtonPressed" HorizontalOptions="FillAndExpand"></SearchBar>  
                   <WebView x:Name="MyWebview"  HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"></WebView>  

    Here is background code. When you click the search button in the keyboard, this webview will show web page. And if you want to keep the user's credentials, please create a custom renderer for webview, enable the Control.Settings.JavaScriptEnabled = true ; and Control.Settings.DomStorageEnabled = true ; like previous question.

       public partial class SchedulePage : ContentPage  
               public SchedulePage()  
               private void webviewSearch_SearchButtonPressed(object sender, EventArgs e)  
                   if (webviewSearch.Text.StartsWith("https://"))  
                       //if url do  start with https://, Search it  
                       MyWebview.Source = webviewSearch.Text;  
                       //if url do not start with https://, add this pre-fix  
                       MyWebview.Source = "https://" + webviewSearch.Text;  

    Best Regards,

    Leon Lu

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Yongqing Huang 241 Reputation points

    Thanks, Leon.

    0 comments No comments