简体   繁体   English

如何使用 Picker 显示带有文本的图像?

[英]How to display an image with text with a Picker?

In WPF you could use a ComboBox to display an image with text (better said any content you want) by changing ItemTemplate.在 WPF 中,您可以使用 ComboBox 通过更改 ItemTemplate 来显示带有文本的图像(最好是您想要的任何内容)。 In MAUI the new name of this control seems to be Picker, but it can just display text.在 MAUI 中,这个控件的新名称似乎是 Picker,但它只能显示文本。 Or am i overlooking something?还是我忽略了什么?

Thanks in advance提前致谢

.Net MAUI don't support image in Picker. .Net MAUI 不支持 Picker 中的图像。 You could use ListView or CollectionView as Jason suggest.您可以按照 Jason 的建议使用 ListView 或 CollectionView。 MAUI ListView has DataTemplate which could be used to define the appearance of each item in the ListView, such as image. MAUI ListView 具有DataTemplate ,可用于定义 ListView 中每个项目的外观,例如图像。 Such like the following (only xaml part)像下面这样(只有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>

For an alternative for image picker in MAUI, we could use a Popup with a listview or navigate to a new page with listview.对于 MAUI 中图像选择器的替代方案,我们可以使用带有列表视图的弹出窗口或使用列表视图导航到新页面。

For more info, you could refer to .Net MAUI ListView .更多信息,您可以参考.Net MAUI ListView

Hope it works for you.希望对你有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM