【问题标题】:UWP community toolkit RoundImageEx image not showingUWP 社区工具包 RoundImageEx 图像未显示
【发布时间】:2023-03-11 14:29:02
【问题描述】:

我的 GridView 有以下 DataTemplate

        <DataTemplate x:Key="GridViewItemTemplate">
        <Grid Margin="5,10" MaxWidth="80">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <!-- Vendor image-->
            <toolkitControls:RoundImageEx IsCacheEnabled="True" PlaceholderSource="/Assets/Samples/AnotherSampleImage.png" PlaceholderStretch="Uniform" Source="/Assets/Samples/SampleImage.png" Stretch="Uniform" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            <TextBlock Grid.Row="1" Padding="0,5,0,0" Text="{Binding NameEn}" HorizontalAlignment="Center" TextWrapping="Wrap" FontSize="{StaticResource SmallTextSize}"/>
        </Grid>
    </DataTemplate>

这里我使用来自 UWP 社区工具包的RoundImageEx 控件。问题是 Image 和 ImagePlaceholder 都没有显示。 我尝试使用工具包中的ImageEx 控件,效果很好。

在 DataTemplate 中使用 ImageEx 的 GridView(它工作得很好)

在 DateTemplate 中使用 RoundImageEx 的 GridView(图像未显示)

这是某种错误还是我做错了什么?

【问题讨论】:

    标签: xaml uwp win-universal-app uwp-xaml windows-community-toolkit


    【解决方案1】:

    方法一:

    为您的RoundImageEx 控件设置HorizontalAlignmentVerticalAlignmentStretch

    代码示例

    <toolkitControls:RoundImageEx IsCacheEnabled="True" PlaceholderSource="/Assets/Samples/AnotherSampleImage.png" 
                                  PlaceholderStretch="Uniform" Source="/Assets/Samples/SampleImage.png" Stretch="Uniform" 
                                  HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
    

    方法二:

    为您的RoundImageEx 控件设置WidthHeight

    代码示例

    <toolkitControls:RoundImageEx IsCacheEnabled="True" PlaceholderSource="/Assets/Samples/AnotherSampleImage.png" 
                                  PlaceholderStretch="Uniform" Source="/Assets/Samples/SampleImage.png" Stretch="Uniform"
                                  Width="100" Height="100"/>
    

    【讨论】:

    • 感谢您的回复!我最终使用了第一种方法,它很有魅力!
    猜你喜欢
    • 1970-01-01
    • 2019-11-09
    • 2021-10-08
    • 2018-02-25
    • 1970-01-01
    • 2020-03-20
    • 1970-01-01
    • 2017-12-17
    • 2019-03-17
    相关资源
    最近更新 更多