【问题标题】:How to display an image with text with a Picker?如何使用 Picker 显示带有文本的图像?
【发布时间】:2023-01-25 16:30:27
【问题描述】:

在 WPF 中,您可以使用 ComboBox 通过更改 ItemTemplate 来显示带有文本的图像(最好是您想要的任何内容)。 在 MAUI 中,这个控件的新名称似乎是 Picker,但它只能显示文本。还是我忽略了什么?

提前致谢

【问题讨论】:

  • Picker 没有模板化,只显示文本内容。您可以使用 ListView 或 CollectionView 来构建您自己的控件
  • 到目前为止,毛伊岛玩得很开心。有一些非常好的新控件..但是旧控件的退化真的很烦人。无法理解它。
  • MAUI 不应该是现有 Windows UI 技术的演变

标签: .net combobox maui picker


【解决方案1】:

.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

希望对你有效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-29
    • 1970-01-01
    • 2012-09-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多