C# 我在为xamarin forns项目使用xaml时出错,并且在呈现控件时出现异常
我正在制作一个应用程序,只需使用一个按钮请求一个url,我想在一个不起作用的WebView上显示url的内容C# 我在为xamarin forns项目使用xaml时出错,并且在呈现控件时出现异常,c#,xaml,xamarin.forms,C#,Xaml,Xamarin.forms,我正在制作一个应用程序,只需使用一个按钮请求一个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:
<?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>
ContentPage不支持多个项目。考虑将Web视图放到StayDay布局中(或者如果需要按钮来覆盖Web视图),使用UpututelayOut.< /P> < P>页面内容不支持多个项目。考虑将Web视图放到StayDay布局中(或者如果需要按钮来覆盖Web视图),使用UpututelayOut.< /P> 内容页只能有一个直接子,所以XAML代码应该是这样的:
<?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>
内容页只能有一个直接子级,因此您的xaml代码应如下所示:
<?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>
你能在MainPage.xaml.cs中提供你的代码吗?你能在MainPage.xaml.cs中提供你的代码吗?我已经尝试将WebView放在StackLayout中,很抱歉它仍然会出现相同的错误我已经尝试将WebView放在StackLayout中,很抱歉它仍然会出现我刚才遇到的错误我不知道我是否理解你的意思我读了错误消息,它说你有一个名为thisActivity
的属性,它是空的。你知道它在哪里吗?不知道那是什么,我没有收到任何名为thisActivity的邮件。我刚刚尝试过代码调整,但仍然出现相同的错误。嗯,尝试将此stacklayout放入contentpage.content标记我不确定我是否理解您的意思。我阅读了错误消息,它说您有一个名为thisActivity
的属性,该属性为空。您知道它在哪里吗是吗?不知道那是什么,我什么都没有