【问题标题】:I am getting an error when using xaml for a xamarin forns project and I am getting an exception occurred while rendering the control将 xaml 用于 xamarin forns 项目时出现错误,并且在呈现控件时出现异常
【发布时间】:2019-02-03 10:43:37
【问题描述】:

enter image description here我正在制作一个简单地使用按钮请求 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>

【问题讨论】:

  • 你能在 MainPage.xaml.cs 中提供你的代码吗?

标签: c# xaml xamarin.forms


【解决方案1】:

ContentPage 不支持多个项目。考虑将 Web 视图放入 StackLayout 或(如果您需要按钮覆盖 Web 视图)使用 AbsoluteLayout。

【讨论】:

  • 我试图将 WebView 放在 StackLayout 中,但很遗憾它仍然给出同样的错误
【解决方案2】:

内容页面只能有一个直接子级,因此您的 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>

【讨论】:

  • 我刚刚试过你的代码调整,它仍然给出同样的错误。
  • 嗯,试试把这个stacklayout放在contentpage.content标签中
  • 我不确定我是否明白你的意思
  • 我阅读了错误消息,它说您有一个名为thisActivity 的属性为空,您知道这是哪里吗?
  • 不知道那是什么,我没有什么叫 thisActivity
猜你喜欢
  • 1970-01-01
  • 2011-05-02
  • 2022-12-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多