我在将xaml用于xamarin forns项目时遇到错误,并且在呈现控件时发生异常

在此输入图像描述我正在制作一个应用程序,该应用程序仅使用按钮请求URL,并且我想在无法正常工作的WebView上显示URL的内容

<?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>


蝴蝶不菲
浏览 131回答 2
2回答

倚天杖

内容页只能有一个直接子项,因此您的 xaml 代码应如下所示:&nbsp; <?xml version="1.0" encoding="utf-8" ?>&nbsp; <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns:local="clr-namespace:SAT"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;x:Class="SAT.MainPage"><StackLayout VerticalOptions="Center"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BackgroundColor="#3C3838">&nbsp; &nbsp; <Button Text="On\\Off"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BackgroundColor="#6FD761"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Margin="70,240,70,0"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x:Name="ToggleRelay1"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Clicked="ToggleRelay1_Clicked"/>&nbsp; &nbsp; <Button Text="On\\Off"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BackgroundColor="#6FD761"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Margin="70,20,70,0"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x:Name="TggleRelay2"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Clicked="TggleRelay2_Clicked"/>&nbsp; &nbsp; <Button Text="Having Trouble ? connect Manualy"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BackgroundColor="#00D06262"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Margin="0,250,0,0"/><WebView x:Name="TestWebView"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;HeightRequest="100"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WidthRequest="100"/>&nbsp; &nbsp; </StackLayout>&nbsp; &nbsp;</ContentPage>

PIPIONE

内容页不支持多个项目。考虑将 Web 视图放入 StackLayout 中,或者(如果需要按钮来覆盖 Web 视图)使用 AbsoluteLayout。
打开App,查看更多内容
随时随地看视频慕课网APP