簡體   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