[英]How to display an image with text with a Picker?
在 WPF 中,您可以使用 ComboBox 通過更改 ItemTemplate 來顯示帶有文本的圖像(最好是您想要的任何內容)。 在 MAUI 中,這個控件的新名稱似乎是 Picker,但它只能顯示文本。 還是我忽略了什么?
提前致謝
.Net MAUI 不支持 Picker 中的圖像。 您可以按照 Jason 的建議使用 ListView 或 CollectionView。 MAUI ListView 具有DataTemplate
,可用於定義 ListView 中每個項目的外觀,例如圖像。 像下面這樣(只有xaml部分)
<ListView x:Name="listView" ItemsSource="{Binding ItemCollection}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<HorizontalStackLayout >
<Label
Text="{Binding Name}"
FontAttributes="Bold"
VerticalTextAlignment="Center"/>
<Image
Source="{Binding ImageSource}"
Aspect="AspectFill"
HeightRequest="30"
WidthRequest="30" />
</HorizontalStackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
對於 MAUI 中圖像選擇器的替代方案,我們可以使用帶有列表視圖的彈出窗口或使用列表視圖導航到新頁面。
更多信息,您可以參考.Net MAUI ListView 。
希望對你有效。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.