當我運行以下代碼時,我收到以下錯誤訊息:
Java.Lang.IllegalStateException: '指定的孩子已經有一個父母。您必須首先在孩子的父母上呼叫 removeView()。
<CarouselView>
<CarouselView.ItemsSource>
<x:Array Type="{x:Type ContentView}">
<ContentView></ContentView>
<ContentView></ContentView>
<ContentView></ContentView>
</x:Array>
</CarouselView.ItemsSource>
<CarouselView.ItemTemplate>
<DataTemplate>
<ContentPresenter Content="{Binding .}"/>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
我不知道您是否可以像這樣設定 CarouselView 的 ItemsSource,但是當我嘗試使用系結時,我會收到相同的錯誤訊息。
uj5u.com熱心網友回復:
根據這個 maui issue,要像這樣直接使用 Maui ContentView,必須將 CarouselView 的Loop屬性設定為false:
<CarouselView Loop="False">
結果:視圖不會形成“回圈”:不能從最后一個視圖滑回第一個視圖。
如果您需要“回圈”行為,另一種方法是不在 xaml 中定義 ItemsSource。相反,有一個不包含 UI 類的 ItemsSource,具有基于每個專案定義(或參考)所需 UI 類的 DataTemplate 或 DataTemplateSelector。[專案是一個“模型”;模板使用系結通過 UI 元素表示該模型。]
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/521420.html
標籤:C#xml毛伊岛
