Allonios
Allonios

Reputation: 43

I am getting an error when using xaml for a xamarin forns project and I am getting an exception occurred while rendering the control

enter image description hereI am making an app that simply request a url using a button, and I want to display the contents of the url on a WebView which is not working

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:SAT"
             x:Class="SAT.MainPage">

    <StackLayout VerticalOptions="Center"
                 BackgroundColor="#3C3838">
        <Button Text="On\\Off" 
                BackgroundColor="#6FD761"
                Margin="70,240,70,0"
                x:Name="ToggleRelay1"
                Clicked="ToggleRelay1_Clicked"/>

        <Button Text="On\\Off" 
                BackgroundColor="#6FD761"
                Margin="70,20,70,0"
                x:Name="TggleRelay2"
                Clicked="TggleRelay2_Clicked"/>

        <Button Text="Having Trouble ? connect Manualy" 
                BackgroundColor="#00D06262"
                Margin="0,250,0,0"/>

    </StackLayout>
    <WebView x:Name="TestWebView"
             HeightRequest="100"
             WidthRequest="100"/>
</ContentPage>

Upvotes: 0

Views: 150

Answers (2)

FreakyAli
FreakyAli

Reputation: 16459

Content Page can only have one direct child so your xaml code should look like this :

  <?xml version="1.0" encoding="utf-8" ?>
  <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:local="clr-namespace:SAT"
         x:Class="SAT.MainPage">

<StackLayout VerticalOptions="Center"
             BackgroundColor="#3C3838">
    <Button Text="On\\Off" 
            BackgroundColor="#6FD761"
            Margin="70,240,70,0"
            x:Name="ToggleRelay1"
            Clicked="ToggleRelay1_Clicked"/>

    <Button Text="On\\Off" 
            BackgroundColor="#6FD761"
            Margin="70,20,70,0"
            x:Name="TggleRelay2"
            Clicked="TggleRelay2_Clicked"/>

    <Button Text="Having Trouble ? connect Manualy" 
            BackgroundColor="#00D06262"
            Margin="0,250,0,0"/>



<WebView x:Name="TestWebView"
         HeightRequest="100"
         WidthRequest="100"/>
    </StackLayout>
   </ContentPage>

Upvotes: 1

Volodymyr Lymar
Volodymyr Lymar

Reputation: 404

ContentPage does not support multiple items. Consider putting the web view into the StackLayout or (if you need the buttons to overlay web view) use the AbsoluteLayout.

Upvotes: 1

Related Questions