c# – .Net MAUI, Unable to access the WebView element in .XAML file, from the .xaml.cs file


I am new to .Net MAUI platform. I am trying to load WebView, but I want to pass the URI source dynamically to the webview. I am using VisualStudio 2022 for Mac. I tried this in my MainPage.xaml file,

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="FirstMaui.MainPage">

    <WebView x:Name="webview"> </WebView>

</ContentPage>

In my MainPage.xaml.cs file,

public MainPage()
    {
        InitializeComponent();
        webview.source = "";
    }

Here, the webview is not exposed in this context. How to overcome this?

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img