我的ListViewItem
里面有Image
。当我尝试绑定图像的Width
和Height
时,图像不会出现,但是当我在XAML代码中手动设置大小时,它工作得很完美。
Xaml代码:
<ListView x:Name="lstPerson" Visibility="Visible" Background="White" Foreground="Black">
<ListView.View>
<GridViewColumn>
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image x:Name="imgThumnailItem" Stretch="Fill" Height="130" Width="{Binding WidthSize}" Source="{Binding ThumbnailItem}"/>
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="100" Header="PC/Username" DisplayMemberBinding="{Binding PcNameUserName}"/>
<GridViewColumn Width="100" Header="Name" DisplayMemberBinding="{Binding Namet}"/>
<GridViewColumn Width="100" Header="Nachname" DisplayMemberBinding="{Binding Nachname}"/>
</ListView.View>
</ListView>
和我的代码背后
// Preparing Image
var img = new BitmapImage();
img.BeginInit();
img.StreamSource = new MemoryStream(_thumbImage);
img.EndInit();
PersonList.Add(new MainFunctions {
PcNameUserName = vorschauObj.PcNameUserName,
Name = vorschauObj.Name,
Nachname = Nachname,
ThumbnailItem = img,
WidthSize = 100,
HeightSize = 100
});
this.lstPersons.ItemSource = PersonList;
MainFunction.cs
public class MainFunctions
{
public string PcNameUserName { get; set; }
public string Name { get; set; }
public string Nachname { get; set; }
public double WidthSize { get; set; }
public double HeightSize { get; set; }
public BitmapImage ThumbnailItem {get;set;}
}