繁体   English   中英

在XAML中将WPF图像设置为属性

[英]Setting a WPF Image in XAML to a property

我的WPF项目中有ListBox,它已设置为“ MyObjectCollection”的数据源。 我设法使ListBox显示我的收藏,而每个项目显示该对象的两个字符串属性。 该对象还包含一个图像,我如何使该图像显示在列表框中?

我目前正在使用以下代码绑定到我的数据源

<UserControl.Resources>
        <DataTemplate x:Key="CustomerTemplate">
            <Border BorderThickness="2" BorderBrush="silver" CornerRadius="5" Padding="1"
                        HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                <Grid>
                    <Image Source="{Binding Artwork}" Tag="{Binding Artwork}" VerticalAlignment="Stretch" ></Image>
                        <TextBlock Text="{Binding Name}"  Foreground="#515151"
                       FontSize="16" HorizontalAlignment="Stretch"
                       FontWeight="Bold" />
                    <TextBlock Text="{Binding Length}" Foreground="#515151" Margin="0,25,0,0"
                       FontSize="10" HorizontalAlignment="Stretch"
                       FontWeight="Bold" />
                </Grid>
            </Border>
        </DataTemplate>
</UserControl.Resources>

谢谢,本

这取决于您收藏中的图像类型。

是文件的路径字符串还是字节数组。

您应该将ValueConverter用于图像绑定。

看看ValueConverter

暂无
暂无

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

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