C#, WPF, vb.Net, vba, SQL Server, Access Programmierer, Excel, ASP Core MVC Webforms Telefon: 07022/9319004 freib. Software Entwickler   Kontakt
#

UWP: Webseite in einem Webview Control laden

 

In UWP Universal Windows Platform nennt sich das Browser-Control Webview UIControl.

Wenn man eine Webseite in diesem Control laden möchte, dann macht man das mit der Webview.Navigate(Uri) Methode

 

 

Beispiel zum Laden einer Webseite

Uri webURL = new Uri(sURL);

ctlBrowser.Navigate(webURL);

 

Dabei benennt sich das Webbrowser Control mit ctlBrowser

<WebView x:Name="ctlBrowser"../>

 

 

 

Video Anleitung zum Anwenden des Code

 

 

Code-Ansicht unter Visual Studio

 

C# Code

 

namespace Stream_Web_Videos_to_TV

{

    public sealed partial class MainPage : Page

    {

        public MainPage()

        {

            this.InitializeComponent();

        }

 

        private void btnStart_Click(object sender, RoutedEventArgs e)

        {

            //------------< btnStart_Click()------------

            //< get URL >

            String sURL = tbxURL.Text;

            if (sURL.IndexOf("http://") == -1) { sURL = "http://" + sURL; }

            //</ get URL >

 

            try

            {

                //--< load website >--

                Uri webURL = new Uri(sURL);

                ctlBrowser.Navigate(webURL);

                //--</ load website >--

            }

            catch (Exception)

            {

                throw;

            }

            //------------</ btnStart_Click()------------

        }

 

 

        #region Events     

        //--------------------< Events >--------------------

        private void ctlBrowser_NavigationStarting(WebView sender, WebViewNavigationStartingEventArgs args)

        {

            ctlProgress.IsActive = true;       

        }

 

        private void ctlBrowser_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args)

        {

            ctlProgress.IsActive = false ;

        }

        //--------------------</ Events >--------------------

        #endregion

    }

}

 

 

 

Xaml der Seite

    <Grid Background="White" >

        <Grid.RowDefinitions>

            <RowDefinition Height="Auto" MinHeight="52"/>

            <RowDefinition/>

        </Grid.RowDefinitions>

 

        <StackPanel Grid.Row="0" Orientation="Horizontal"  HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Background="#f0f0f0" >

            <TextBlock Text="URL:" />

            <TextBox  x:Name="tbxURL" Text=""  Width="600"/>

            <Button x:Name="btnStart" Content="Start" Click="btnStart_Click"></Button>

            <ProgressRing x:Name="ctlProgress" Height="30" Width="30" />

        </StackPanel>

 

        <WebView x:Name="ctlBrowser" Grid.Row="1"  HorizontalAlignment="Stretch" VerticalAlignment="Stretch" NavigationStarting="ctlBrowser_NavigationStarting" NavigationCompleted="ctlBrowser_NavigationCompleted" />

 

    </Grid>

 

 

Mobile
»
UWP: Anzeigen eines Videos vom Internet
»
UWP: Webseite in einem Webview Control laden
»
UWP Code: Webcam Recorder in mp4

.

Jobs, Projekte, Angebote für Freiberufler, Selbstständig an Raimund.Popp@Microsoft-Programmierer.de