绑定图像宽度和高度

时间:2014-02-02 15:34:41

标签: c# wpf binding

我的ListViewItem里面有Image。当我尝试绑定图像的WidthHeight时,图像不会出现,但是当我在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;}
    }

0 个答案:

没有答案