簡體   English   中英

使用WPF從ListView內的類綁定BitmapImage對象

[英]Binding a BitmapImage object from a class inside a ListView with WPF

我對WPF應用程序有疑問。 我想將一個類內部的BitmapImage對象綁定到XAML內的Image對象。 所以我這樣做:(我直接將此類添加到ListView中):

Public Sub New(ByVal Adress As String, ByVal ISAF As Boolean)
    IWorking = showIcon(sName.Substring(sName.LastIndexOf(".")))
    Dim IconMemStream As New MemoryStream
    IWorking.ToBitmap.Save(IconMemStream, System.Drawing.Imaging.ImageFormat.Bmp)
    sImage = New BitmapImage
    sImage.BeginInit()
    sImage.StreamSource = IconMemStream
    sImage.EndInit()
    IconMemStream.Close()
    RaiseEvent PropertyChanged(Me, New System.ComponentModel.PropertyChangedEventArgs("Image"))
End Sub

在XAML內部,我正在使用以下代碼:

            <ListView.View>
                <GridView>
                    <GridViewColumn>
                    <GridViewColumn.CellTemplate>
                            <DataTemplate>
                            <StackPanel HorizontalAlignment="Left">
                                <Image Source="{Binding Image}" Width="32" Height="32" />
                                <Label Content="{Binding Name}" />
                                </StackPanel>
                        </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                </GridView>

名稱顯示,但位圖不顯示。 我檢查了sImage對象是否具有位圖,並且是否具有。 但是,問題似乎出在綁定中。

有任何想法嗎 ?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM