最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

.net - DotNet MAUI Pages - Stack Overflow

programmeradmin1浏览0评论

Good day, I am trying to understand the new dotnet MAUI page layout. I want to put a menu bar at the top of the page, And I keep getting the same error: "The property Content is set more than once."

Below is my code of the mainPage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns=";
         xmlns:x=";
         xmlns:local="clr-namespace:testpage"
         xmlns:shared="clr-namespace:testpage.Shared;assembly=testpage.Shared"
         x:Class="testpage.MainPage"
         BackgroundColor="{DynamicResource PageBackgroundColor}">

<StackLayout Padding="20" Spacing="10" VerticalOptions="Center" HorizontalOptions="Center">
    <Label Text="This is Just a test!"
            FontSize="Large"
            HorizontalOptions="Center"
            VerticalOptions="Center" />
</StackLayout>

<BlazorWebView x:Name="blazorWebView" HostPage="wwwroot/index.html">
    <BlazorWebView.RootComponents>
        <RootComponent Selector="#app" ComponentType="{x:Type shared:Routes}" />
    </BlazorWebView.RootComponents>
</BlazorWebView>

Good day, I am trying to understand the new dotnet MAUI page layout. I want to put a menu bar at the top of the page, And I keep getting the same error: "The property Content is set more than once."

Below is my code of the mainPage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft/dotnet/2021/maui"
         xmlns:x="http://schemas.microsoft/winfx/2009/xaml"
         xmlns:local="clr-namespace:testpage"
         xmlns:shared="clr-namespace:testpage.Shared;assembly=testpage.Shared"
         x:Class="testpage.MainPage"
         BackgroundColor="{DynamicResource PageBackgroundColor}">

<StackLayout Padding="20" Spacing="10" VerticalOptions="Center" HorizontalOptions="Center">
    <Label Text="This is Just a test!"
            FontSize="Large"
            HorizontalOptions="Center"
            VerticalOptions="Center" />
</StackLayout>

<BlazorWebView x:Name="blazorWebView" HostPage="wwwroot/index.html">
    <BlazorWebView.RootComponents>
        <RootComponent Selector="#app" ComponentType="{x:Type shared:Routes}" />
    </BlazorWebView.RootComponents>
</BlazorWebView>
Share Improve this question asked Mar 18 at 14:26 Kenneth GoodwinKenneth Goodwin 231 silver badge2 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

a ContentPage can only have a single child element. You have two. To fix this, move your BlazorWebView inside of the StackLayout

<StackLayout Padding="20" Spacing="10" VerticalOptions="Center" HorizontalOptions="Center">
    <Label Text="This is Just a test!"
            FontSize="Large"
            HorizontalOptions="Center"
            VerticalOptions="Center" />

    <BlazorWebView x:Name="blazorWebView" HostPage="wwwroot/index.html">
       <BlazorWebView.RootComponents>
          <RootComponent Selector="#app" ComponentType="{x:Type shared:Routes}" />
       </BlazorWebView.RootComponents>
    </BlazorWebView>

</StackLayout>
发布评论

评论列表(0)

  1. 暂无评论