我有兩個視圖網格視圖和側視圖。我想在網格視圖中匯入我的側視圖,所以我在這里添加了命名空間,然后我在網格中設定了它。
網格視圖代碼:
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="GridDemo.View.GridView"
xmlns:v="clr-namespace:GridDemo.View"
>
<Grid RowDefinitions="auto,auto"
ColumnDefinitions=".5*,.5*">
<Label Text="Hello from grid view" Grid.Column="0" Grid.Row="0"/>
<v:SideView Grid.Column="1" Grid.Row="1"/>
</Grid>
側視圖代碼:
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="GridDemo.View.SideView"
Title="SideView">
<VerticalStackLayout>
<Label
Text="Welcome to .NET MAUI!"
VerticalOptions="Center"
HorizontalOptions="Center" />
</VerticalStackLayout>
但它不作業。這是實作這一目標的正確方法嗎?還是我做錯了?
uj5u.com熱心網友回復:
我在android和mac平臺上測驗過,側視圖可以添加到Grid. 根據例外訊息:
頁面的父級必須是頁面
Maui 是一個跨平臺的框架,其中的控制元件是不同平臺上的不同控制元件和視圖處理程式。ContentPage不能作為Gridwindows 平臺上的子視圖添加。
但是您可以將SideView's 型別更改為 contentview。如:
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="GridDemo.View.SideView">
<VerticalStackLayout>
<Label
Text="Welcome to .NET MAUI!"
VerticalOptions="Center"
HorizontalOptions="Center" />
</VerticalStackLayout>
</ContentView>
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/525983.html
標籤:。网.net-maui
